2013-02-19 49 views
0

任何人都可以帮助我。我已经设法使RowEditing的功能正常工作,并且现在正试图让RowUpdating继续。我的GridView的设置是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预编译存储过程的参数列下面的ASP呃。通常的方法是按照下面的,但我努力让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但即时通讯努力获得在GridView rRowEditing值代入变量/参数传递给SqlCommand。

ID感兴趣的:

DataBinder - BindCountryGrid 
    DataReader - CountryGridSelectReader 

回答

0

工作了最后:

后面的代码需要resenble如下:

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(); 


     }