0

任何人都可以帮助我。我已经设法让 RowEditing 的功能正常工作,现在正试图让 RowUpdating 继续工作。我的 gridview 设置如下

<asp:GridView ID="CountryGridView" runat="server" AutoGenerateColumns="false" CssClass="mGrid" OnRowEditing="CountryGridView_RowEditing" OnRowCancelingEdit="CountryGridView_RowCancelingEdit" >
                    <Columns>
                        <asp:BoundField ReadOnly="true" DataField="i_SK_Accom" HeaderText="i_SK_Accom" Visible="false" />
                        <asp:BoundField ReadOnly="true" DataField="Accom_Code" HeaderText="Accom Code" />
                        <asp:BoundField ReadOnly="true" DataField="Accom_Name" HeaderText="Accom Name" />
                        <asp:BoundField DataField="OP49_Required" HeaderText="OP49 Required?" />
                        <asp:BoundField DataField="Weekly" HeaderText="Weekly" />
                        <asp:BoundField DataField="Daily" HeaderText="Daily" />
                        <asp:CommandField ShowEditButton="true" ButtonType="Image" EditImageUrl="~/Images/Edit.gif" UpdateImageUrl="~/Images/save.png" CancelImageUrl="~/Images/cancel.png" ControlStyle-CssClass="ImageButton" />
                    </Columns>
                </asp:GridView>

我试图让 RowUpdating 传递由于要更新为 MS SQL 上预编译存储过程的参数的列。通常的方法如下,但我正在努力让 gridview 工作。

SqlCommand commEditConsultant = new SqlCommand("IFACE_JFA_ACCOM", conn.sbConn);
    commEditConsultant.CommandType = CommandType.StoredProcedure;

    try
    {
        commEditConsultant.Parameters.Add("@Statement", SqlDbType.VarChar).Value = "AccomUpdate";
        commEditConsultant.Parameters.Add("@Page", SqlDbType.VarChar).Value = "OP49";
        commEditConsultant.Parameters.Add("@PC_Username", SqlDbType.VarChar).Value = HttpContext.Current.User.Identity.Name.ToString();
        commEditConsultant.Parameters.Add("@Season_Name", SqlDbType.VarChar).Value = Season.Text;
        commEditConsultant.Parameters.Add("@i_SK_Accom", SqlDbType.VarChar).Value = Request["i_SK_Accom"].Trim().ToString();
        commEditConsultant.Parameters.Add("@OP49_Required", SqlDbType.VarChar).Value = ddl_OP49Required.SelectedItem.Value;
        commEditConsultant.Parameters.Add("@Weekly", SqlDbType.VarChar).Value = ddl_OP49Weekly.SelectedItem.Value;
        commEditConsultant.Parameters.Add("@Daily", SqlDbType.VarChar).Value = ddl_OP49Daily.SelectedItem.Value;
    }

上面指定的字段与 gridview 所需的字段相同,但我正在努力将 gridviewrRowEditing值转换为变量/参数以传递给 SQLCommand。

感兴趣的ID:

  DataBinder - BindCountryGrid
  DataReader - CountryGridSelectReader
4

1 回答 1

0

最终解决了:

背后的代码需要重新启用以下内容:

protected void CountryGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Label Textbox_Accom = (Label)gv_CountryGridView.Rows[e.RowIndex].FindControl("lbl_Accom_Code");
            Label Textbox_Accom_Name = (Label)gv_CountryGridView.Rows[e.RowIndex].FindControl("lbl_Accom_Name");
            DropDownList Textbox_OP49 = (DropDownList)gv_CountryGridView.Rows[e.RowIndex].FindControl("ddl_OP49");
            DropDownList Textbox_Weekly = (DropDownList)gv_CountryGridView.Rows[e.RowIndex].FindControl("ddl_Weekly");
            DropDownList Textbox_Daily = (DropDownList)gv_CountryGridView.Rows[e.RowIndex].FindControl("ddl_Daily");
            TextBox Textbox_FRRStartDate = (TextBox)gv_CountryGridView.Rows[e.RowIndex].FindControl("txt_FRRStartDate");

            SqlCommand commEditConsultant = new SqlCommand("IFACE_JFA_ACCOM", ConnJFA);
            commEditConsultant.CommandType = CommandType.StoredProcedure;

            commEditConsultant.Parameters.Add("@Statement", SqlDbType.VarChar).Value = "AccomGridUpdate";
            commEditConsultant.Parameters.Add("@Page", SqlDbType.VarChar).Value = "OP49";
            commEditConsultant.Parameters.Add("@PC_Username", SqlDbType.VarChar).Value = HttpContext.Current.User.Identity.Name.ToUpper().ToString();
            commEditConsultant.Parameters.Add("@Season_Name", SqlDbType.VarChar).Value = txt_Season.Text;
            commEditConsultant.Parameters.Add("@Accom_Code", SqlDbType.VarChar).Value = Textbox_Accom.Text;
            commEditConsultant.Parameters.Add("@i_FK_SeasonID", SqlDbType.VarChar).Value = Request["i_FK_SeasonID"].Trim().ToString();
            commEditConsultant.Parameters.Add("@OP49_Required", SqlDbType.VarChar).Value = Textbox_OP49.Text;
            commEditConsultant.Parameters.Add("@Weekly", SqlDbType.VarChar).Value = Textbox_Weekly.Text;
            commEditConsultant.Parameters.Add("@Daily", SqlDbType.VarChar).Value = Textbox_Daily.Text;
            commEditConsultant.Parameters.Add("@FRR_StartDate", SqlDbType.VarChar).Value = Textbox_FRRStartDate.Text;

            ConnJFA.Open();
            commEditConsultant.ExecuteNonQuery();
            gv_CountryGridView.EditIndex = -1;
            Error_Dashboard.Text = Textbox_Accom.Text + " - " + Textbox_Accom_Name.Text + " Updated Successfully!";
            ConnJFA.Close();
            BindCountryGrid();


        }
于 2013-11-01T13:02:10.750 回答