Click here to Skip to main content
12,999,633 members (42,208 online)
Rate this:
Please Sign up or sign in to vote.
See more: Code
<asp:GridView ID="GridView1" runat="server" 
                     <asp:ImageButton ID="imgbtnDelete" runat="server" CommandName="Cancel" ImageUrl="~/MineBlast/Image/delete.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
                    <asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/MineBlast/Image/update.jpg"  ToolTip="Update" Height="20px" Width="20px" />
            <%-- <asp:BoundField DataField="HAU_ID" HeaderText="HAU ID" />--%>
            <asp:TemplateField  HeaderText="HAUID">
                    <asp:TextBox ID="TXtHauID" runat ="server" Text='<%#Eval("HAU_ID") %>'  ></asp:TextBox>
            <asp:TemplateField  HeaderText="Diesel">
                    <asp:TextBox ID="TextID1" runat ="server" Text='<%#Eval("HAU_DIESELISSUED") %>'  ></asp:TextBox>
            <asp:TemplateField HeaderText ="REGNO">
                <ItemTemplate >
                    <asp:TextBox ID="TextID2" runat ="server" Text ='<%#Eval("HAU_REGISID") %>'></asp:TextBox>
            <asp:TemplateField HeaderText="TONNAGE">
                    <asp:TextBox ID="TextID3"   runat ="server" Text ='<%#Eval("HAU_TONNAGE") %>' ></asp:TextBox>
            <asp:TemplateField HeaderText="TYPE" >
                    <asp:TextBox ID="TextID4" runat ="server" Text ='<%#Eval("WORD") %>'></asp:TextBox>
             <asp:TemplateField HeaderText="TRIPS" >
                    <asp:TextBox ID="TextID5" runat ="server"  Text ='<%#Eval("HAU_TRIPS") %>'></asp:TextBox>
             <asp:TemplateField HeaderText="CREATE DATE"  >
                    <asp:TextBox ID="TextID6" runat ="server" Text ='<%#Eval("CREATED_DATE") %>' ></asp:TextBox>
      <FooterStyle HorizontalAlign="Center" />
      <RowStyle HorizontalAlign="Center" />

In aspx.cs
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        // string userid = GridView1.DataKeys[e.RowIndex].Values["HAU_ID"].ToString();  
          string  myfile  = GridView1.Rows[e.RowIndex].Cells[1].FindControl("HAU_ID").ToString () ; 
      //  int HAUID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["HAU_ID"].ToString());
        TextBox TextID1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextID1");
        TextBox TextID2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextID2");
        TextBox TextID3 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextID3");
        TextBox TextID4 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextID4");
        TextBox TextID5 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextID5");
        TextBox TextID6 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextID6");
        //SqlCommand cmd = new SqlCommand("update Employee_Details set City='" + txtcity.Text + "',Designation='" + txtDesignation.Text + "' where UserId=" + userid, con);
        //lblresult.ForeColor = Color.Green;
        //lblresult.Text = username + " Details Updated successfully";
        //gvDetails.EditIndex = -1;
Posted 6-Dec-12 2:01am
Tadit Dash 6-Dec-12 10:07am
Hi Manoj,

Have you tried with DataKeyNames suggested by @Krunal Rohit, in his answer ?
You need to add the property in GridView as DataKeyNames="ID", which you have nothing now like DataKeyNames="".
So, try doing this and let us know if it worked or not.

manoj s sherje 6-Dec-12 23:43pm
Thank sir i am miss this dataKeyNames give id thank you very much
Tadit Dash 7-Dec-12 1:18am
You are most welcome buddy. Anytime my pleasure. :)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values["ID"].ToString());

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100