Get column values โ€‹โ€‹in Check_changed Checkbox event in gridview

I have a grid view that contains a date and time string in the dataBound field and a checkbox in the element's template field. Now, when the user checks any checkbox, I want to make the isChecked field of my data table (which is the data source for gridview and isCheck added programmatically) true / false accourdingly. How can I get the date time string from gridview based on checked / uncheked ??

+3
source share
1 answer

You can do as ...

<asp:TemplateField HeaderText="Date">
    <ItemTemplate>
      <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
     <asp:TemplateField HeaderText="Checkbox">
        <ItemTemplate>
           <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" 
                    oncheckedchanged="CheckBox1_CheckedChanged" />
         </ItemTemplate>
</asp:TemplateField>

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
   String Date = ((Label)((CheckBox)sender).Parent.FindControl("lblDate")).Text;
}
+2
source

All Articles