By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

Code Behind error for checkbox in datagrid

P: n/a
I have the following asp:checkbox as a row in my datagrid. and im trying to
write code on the onCheckedChanged event of it. The code im trying to write
is incorrect as im getting build errors. What im trying to do is populate a
label on my aspx page with the contents of the row in the database which I
have checked. When I uncheck the checkbox I want the label to be set to
blank so as it can be populated again when another checkbox in the datagrid
is ticked. The html for the checkbox is below along with the code-behind
page. Can someone tell me what i've done wrong and how I can fix this.
Thanks for any help anyone can give.

<asp:TemplateColumn HeaderImageUrl="../Images/Tick.gif">
<HeaderStyle HorizontalAlign="Center" Height="20px" Width="10px"
CssClass="dgHeader" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10px"
VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkSelection" Runat="server" AutoPostBack="True"
OnCheckedChanged="myFunction"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

public void myFunction(object sender, System.EventArgs e)
{
this.lbldatagridrow.Text = e.Item.Cells[0].Text;
}
Build Error: -
'System.EventArgs' does not contain a definition for 'Item'

Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
It looks like your event handler has the wrong signature. If you want to reference the datagrid row (item) corresponding to the checked checkbox, then you'll have to pass the item along with the CheckBox's CheckedChange event.
The System.EventArgs class has no property called Item. That's where your compile failure is stemming from. The Item property is typically associated with custom event arguments (like those provided when a DataGrid row is selected).

Hope this helps.
I have the following asp:checkbox as a row in my datagrid. and im trying to
write code on the onCheckedChanged event of it. The code im trying to write
is incorrect as im getting build errors. What im trying to do is populate a
label on my aspx page with the contents of the row in the database which I
have checked. When I uncheck the checkbox I want the label to be set to
blank so as it can be populated again when another checkbox in the datagrid
is ticked. The html for the checkbox is below along with the code-behind
page. Can someone tell me what i've done wrong and how I can fix this.
Thanks for any help anyone can give.

<asp:TemplateColumn HeaderImageUrl="../Images/Tick.gif">
<HeaderStyle HorizontalAlign="Center" Height="20px" Width="10px"
CssClass="dgHeader" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10px"
VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkSelection" Runat="server" AutoPostBack="True"
OnCheckedChanged="myFunction"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

public void myFunction(object sender, System.EventArgs e)
{
this.lbldatagridrow.Text = e.Item.Cells[0].Text;
}
Build Error: -
'System.EventArgs' does not contain a definition for 'Item'


User submitted from AEWNET (http://www.aewnet.com/)
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.