Click here to Skip to main content
15,883,990 members

How to select ID in GridvIew in one variable following My Code

manoj s sherje asked:

Open original thread
Asp.net Code
XML
<asp:GridView ID="GridView1" runat="server" 
                    AutoGenerateColumns="False"
                    CssClass="mGrid" 
                    DataKeyNames="" 
                    ShowFooter="true" 
                    Width="400px"
                    onrowdeleting="gvDetails_RowDeleting"
                    onrowupdating="gvDetails_RowUpdating">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                     <asp:ImageButton ID="imgbtnDelete" runat="server" CommandName="Cancel" ImageUrl="~/MineBlast/Image/delete.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
                </ItemTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/MineBlast/Image/update.jpg"  ToolTip="Update" Height="20px" Width="20px" />
                    </ItemTemplate>
            </asp:TemplateField>
            <%-- <asp:BoundField DataField="HAU_ID" HeaderText="HAU ID" />--%>
            <asp:TemplateField  HeaderText="HAUID">
                <ItemTemplate>
                    <asp:TextBox ID="TXtHauID" runat ="server" Text='<%#Eval("HAU_ID") %>'  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField  HeaderText="Diesel">
                <ItemTemplate>
                    <asp:TextBox ID="TextID1" runat ="server" Text='<%#Eval("HAU_DIESELISSUED") %>'  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="REGNO">
                <ItemTemplate >
                    <asp:TextBox ID="TextID2" runat ="server" Text ='<%#Eval("HAU_REGISID") %>'></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="TONNAGE">
                <ItemTemplate>
                    <asp:TextBox ID="TextID3"   runat ="server" Text ='<%#Eval("HAU_TONNAGE") %>' ></asp:TextBox>
                    </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="TYPE" >
                <ItemTemplate>
                    <asp:TextBox ID="TextID4" runat ="server" Text ='<%#Eval("WORD") %>'></asp:TextBox>
                </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="TRIPS" >
                <ItemTemplate>
                    <asp:TextBox ID="TextID5" runat ="server"  Text ='<%#Eval("HAU_TRIPS") %>'></asp:TextBox>
                </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="CREATE DATE"  >
                <ItemTemplate>
                    <asp:TextBox ID="TextID6" runat ="server" Text ='<%#Eval("CREATED_DATE") %>' ></asp:TextBox>
                </ItemTemplate>
             </asp:TemplateField>
      </Columns>
      <FooterStyle HorizontalAlign="Center" />
      <RowStyle HorizontalAlign="Center" />
</asp:GridView>

In aspx.cs
C#
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");
        //con.Open();
        //SqlCommand cmd = new SqlCommand("update Employee_Details set City='" + txtcity.Text + "',Designation='" + txtDesignation.Text + "' where UserId=" + userid, con);
        //cmd.ExecuteNonQuery();
        //con.Close();
        //lblresult.ForeColor = Color.Green;
        //lblresult.Text = username + " Details Updated successfully";
        //gvDetails.EditIndex = -1;
        //BindEmployeeDetails();  
}
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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