Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get DataKey value on check box checked event in a GridView

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.55k
    Comment on it

    Get DataKey value on check box checked event in a GridView

    Here is the .aspx code for the following:-

      <asp:GridView ID="grdTest" runat="server" AutoGenerateColumns="False" DataKeyNames="ID">
        <Columns>
        <asp:TemplateField HeaderText="Is Released" >
         <ItemTemplate>
        <asp:CheckBox ID="chkReleased" runat="server" OnCheckedChanged="chkReleased&#95;CheckedChanged" AutoPostBack="true" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    Write the following code on C# page.

     protected void chkReleased_CheckedChanged(object sender, EventArgs e)
        {
        CheckBox chkreleased = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chkreleased.NamingContainer;
        string Id = 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: