Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • how to get a label Text or DataKey value on button click in a gridview

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.57k
    Comment on it

    Get a label Text or DataKey value on button click in a gridview

    Write the .aspx code as below:--

     <asp:GridView ID="grdtest" runat="server" AutoGenerateColumns="false" 
      <Columns>
      <asp:TemplateField>
      <ItemTemplate>
     <asp:Label ID="lblid" runat="server" ></asp:Label>
     <asp:Button ID="btnRemove" runat="server"  OnClick="btnRemoveclicked" />
       </ItemTemplate>
      </asp:TemplateField>
       </Columns>
       </asp:GridView>
    

    Write the C# code to get the DataKey value and LabelText

    protected void btnRemoveclicked(object sender, EventArgs e)
          {
          Button button1= (Button)sender;
          GridViewRow row = (GridViewRow)button1.Parent.Parent;
          labeltext= ((Label)row.FindControl("lblid") as Label).Text;
          string  string datakey = grdtest.DataKeys[row.RowIndex].Value.ToString();
          }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: