Code Behind error for checkbox in datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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'
 
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/)
 
Back
Top