0

カートに追加機能に取り組んでおりGridView、ページングを有効にしたコントロールを追加しました。ではGridView、数量をテキスト ボックスに表示し、そのテキスト ボックスのOnTextChangedイベントを処理します。ここでの問題は、変更された数量テキストをセッションまたはビュー ステートでどの行に保持して、更新してGridViewそのデータを再度 にバインドできるGridViewかです。

ここではGridView、id gvMaster で撮影しました。

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;
}

ページングを有効にして、変更された数量値をグリッドに表示したいと考えています。

4

2 に答える 2

0

あなたのコードが実際に何をしているのか理解できません。ただし、コントロールの状態などの情報は、Sessionに保持しないでください。代わりにViewStateを使用してください。

于 2011-01-02T10:52:13.207 に答える
-1

質問に C# Asp.net タグを追加します。また、 asp.net で n-tier programming/mvc を調べてください。コードを何度も改善するのに役立ちます

于 2011-01-02T05:58:33.017 に答える