Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Update")
        {

            int RowIndex = Convert.ToInt32(e.CommandArgument);
          
            GridViewRow row = (GridViewRow)GridViewDept.Rows[RowIndex];
            
            Label deptno = (Label)row.FindControl("lblDeptNO" );
            TextBox deptname = (TextBox)row.FindControl("txtDeptName");
           
            TextBox deptloc = (TextBox)row.FindControl("txtloc");
            cn.Open();
            string query = "update dept set dname'" + deptname.Text + "','" + deptloc.Text + "' where deptno='" + deptno.Text + "'";
            cm = new SqlCommand(query, cn);
            cm.ExecuteNonQuery();
            cn.Close();
            ShowRecords();
        }
protected void GridViewDept_RowEditing(object sender, GridViewEditEventArgs e)
   {

       GridViewDept.EditIndex = e.NewEditIndex;
       GridViewDept.FindControl("txtDeptNO").Visible = true;
  GridViewDept.FindControl("txtDeptName").Visible = true;
  GridViewDept.FindControl("txtloc").Visible = true;

       ShowRecords();
   }
Posted
Comments
Siva Hyderabad 20-May-14 2:17am    
You should use
EditItemTemplate

<asp:TemplateField HeaderText="Amount Received" ItemStyle-HorizontalAlign="Center">
<edititemtemplate>
<asp:TextBox runat="server" ID="txt_amtrec" Width="90px" onkeypress="return validatenumerics(event)">
<asp:RequiredFieldValidator ID="RFVrecdate1" runat="server" ControlToValidate="txt_amtrec"
Display="None" ErrorMessage="Must Enter Received Amount" ValidationGroup="duereport">
<asp:ValidatorCalloutExtender ID="VCErecdate1" runat="Server" TargetControlID="RFVrecdate1" />

Siva Hyderabad 20-May-14 2:20am    
you should change

GridView1_RowCommand to GridViewDept_RowCommand..
Event is incorrect
Ajesh1986 20-May-14 4:17am    
upload your .aspx page
Ajesh1986 20-May-14 4:19am    
You should have to use Template field for that and under EditItem template u can have the textbox
example
<edititemtemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("ProductCategory")%>'

upload ur HTML or .aspx page to check urs

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900