Capture CheckBox Click Event

N

news.microsoft.com

I have a datagrid with a checkbox column. The column is bound to adatabase,
and I have no problem capturing a click event on the checkbox using the
OnCheckChanged event handler.

Here is a sample of the html used to build the column:
<asp:TemplateColumn HeaderText="Crew Chief?">
<HeaderStyle HorizontalAlign="Center" Width="40px"
VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:checkbox id=chkChief runat="server"
cssclass="FormFieldText2"
OnCheckedChanged="cbChief_Clicked"
COMMANDARGUMENT='<%#Container.DataItem("SAN") %>'
AutoPostBack=True Checked='<%#
bSetCheckValue(Container.DataItem("IsChief"))%>'>
</asp:checkbox>
</ItemTemplate>
</asp:TemplateColumn>

The event handler function fires and I get a reference to the checkbox
object that was clicked.

The problem is that I am trying to get a reference to the row that the
checkbox was clicked in to retrieve the datakey value. I know I could loop
through the entire dataitem list and find the match, but what I was trying
to do was pass the datakey value for the row as a command arguement, so that
I can use the datakey value directly in the event handler.

Has anyone been able to make this work?

Thanks,
Marc.
 
M

Marc Rivait

Here is the answer to my post. Thanks to Michael.

protected void cbChief_Clicked(object sender, EventArgs e) {

string _val = ((CheckBox)sender).Attributes["COMMANDARGUMENT"]; // Here we
received value in the attribute of checkbox.

foreach(DatagridItem dr in Datagring.Items)

{

// your code.

}

}



The Best Regards,

Net Developer

Michael Tkachev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top