LINQ:GridView正在更新具有相同值的每一行



我想在不使用普通更新命令的情况下更新gridview时运行一些方法。我相信我可以使用rowupdating进行。

 protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int selectedRowIndex = e.RowIndex;
        TextBox txtID = (TextBox)GridView2.Rows[e.RowIndex].FindControl("TextBox13");
        TextBox txtDate1 = (TextBox)GridView2.Rows[e.RowIndex].FindControl("txtDate1");
        TextBox txtDate2 = (TextBox)GridView2.Rows[e.RowIndex].FindControl("txtDate2");
        Label duration = (Label)GridView2.Rows[e.RowIndex].FindControl("Label13");
        Label diff = (Label)GridView2.Rows[e.RowIndex].FindControl("Label14");
        Label remainder = (Label)GridView2.Rows[e.RowIndex].FindControl("Label15");
        Label expiry = (Label)GridView2.Rows[e.RowIndex].FindControl("Label17");
        DropDownList ddlName = (DropDownList)GridView2.Rows[e.RowIndex].FindControl("ddlName");
        DropDownList ddlType = (DropDownList)GridView2.Rows[e.RowIndex].FindControl("ddlType");
        DropDownList ddlLocation = (DropDownList)GridView2.Rows[e.RowIndex].FindControl("ddlLocation");
        DropDownList ddlFee = (DropDownList)GridView2.Rows[e.RowIndex].FindControl("ddlFee");
         //dc.updateArchive(Variables goes here);
         GridView2.DataBind();
         GridView2.EditIndex = -1;  }

弄乱后,我能够从所选行(我单击编辑的行)中读取值模式(选择?)。

我需要抓住正在编辑的行的数据。我该如何完成?

您可以像这样使用

var key=GridView2.DataKeys[selectedRowIndex].Value;

,请确保您的datakeynames中有CC_1。

datakeynames="LocationID"
//name of you actual primary key field in you select data source.

最新更新