私はカートに追加機能に取り組んでおり、ページングを有効にしてGridView
コントロールを追加しました。 GridView
では、数量をテキストボックスに表示し、そのテキストボックスのOnTextChanged
イベントを処理します。ここで問題は、変更された数量のテキストをセッションまたはビューの状態とどの行に保存してGridView
を更新し、そのデータをGridView
に再びバインドできるかです。ページングを有効にしたGridViewコントロールからすべてのGridViewRowを取得するにはどうすればよいですか?
ここでは、idがgvMasterのGridView
を使用しました。
protected void txtQuantity_TextChanged(object sender, EventArgs e)
{
gvMaster.DataSource = ProductDetailsGridMaster();
gvMaster.AllowPaging = true;
gvMaster.DataBind();
}
public DataTable ProductDetailsGridMaster()
{
DataTable dtProducts = new DataTable();
dtProducts.Columns.Add("ProductId");
dtProducts.Columns.Add("ProductName");
dtProducts.Columns.Add("ProductPrice");
dtProducts.Columns.Add("Quantity");
dtProducts.Columns.Add("Price");
gvMaster.AllowPaging = false;
if (Session["dtProducts"] != null)
{
GridView gv = new GridView();
gv.DataSource = Session["dtProducts"];
gvMaster.DataSource = gv.DataSource;
gvMaster.DataBind();
lblMessage.Text = "";
}
//GridView gvc = (GridView)Page.FindControl("gvMaster");
for (int i = 0; i < gvMaster.Rows.Count; i++)
{
Label lblProductId = (Label)gvMaster.Rows[i].Cells[0].FindControl("lblProductId");
Label lblProductName = (Label)gvMaster.Rows[i].Cells[1].FindControl("lblProductName");
Label lblProductPrice = (Label)gvMaster.Rows[i].Cells[2].FindControl("lblProductPrice");
//Label lblssno = (Label)gv.Rows[i].Cells[2].FindControl("lblSSNo");
TextBox txtQuantity = (TextBox)gvMaster.Rows[i].Cells[3].FindControl("txtQuantity");
//TextBox mastertxtQuantity = (TextBox)gvMaster.Rows[i].Cells[3].FindControl("txtQuantity");
Label lblPrice = (Label)gvMaster.Rows[i].Cells[4].FindControl("lblPrice");
var Price = decimal.Parse(lblProductPrice.Text) * decimal.Parse(txtQuantity.Text);
lblPrice.Text = Price.ToString();
DataRow dr = dtProducts.NewRow();
dr["ProductId"] = lblProductId.Text;
dr["ProductName"] = lblProductName.Text;
dr["ProductPrice"] = lblProductPrice.Text;
dr["Quantity"] = txtQuantity.Text;
dr["Price"] = lblPrice.Text;
dtProducts.Rows.Add(dr);
}
Session["dtProducts"] = dtProducts;
return dtProducts;
}
変更された数量値をページングを有効にしてグリッドに表示したいとします。
なぜ理由なしで投票しますか? – Arjang
私はそれをダウン投票していたわけではありませんでしたが、私はなぜそれが見えるのですか?答えの最初のビットは、あなた自身で編集したり、コメント欄と2番目の部分に入れることができますが、丁寧で幅広いRTFMであり、決して役に立たないことはありません。 – Jules
@ジュール:それに応じて私の答えを編集すると感謝しています。それとも、削除する方が良いと思うか。私はRTFMではなく、どこを見ているかを指摘しようとしていました。誰かが私に「これらのキーワード」を求めて追いかけてくると言ったら、私は必要なすべてのものを、すべての詳細を私に説明しようと思っているのではなく、 – Arjang