0

So i have the following method

protected void isDirector_CheckedChanged(object sender, EventArgs e)
{
    HtmlTableRow row = (HtmlTableRow)e.Item.FindControl("today");

But getting error

CS0117: 'System.EventArgs' does not contain a definition for 'Item'

EDIT :

<asp:UpdatePanel ID="UpdatePanel2" 
                        runat="server" 
                        UpdateMode="Conditional">
                        <ContentTemplate>
            <asp:RadioButtonList ID="isDirector" RepeatDirection="Horizontal" runat="server" AutoPostBack="True" OnSelectedIndexChanged="isDirector_CheckedChanged">
                <asp:ListItem Text="Yes" Value="True" selected></asp:ListItem>
                <asp:ListItem Text="No" Value="False"></asp:ListItem>
            </asp:RadioButtonList>
            </ContentTemplate>
                        </asp:UpdatePanel>
 <asp:UpdatePanel
<ContentTemplate>

    <tr runat="server" id="test">
        <td>Director First Name:</td>
        <td><asp:TextBox ID="DirectorfirstNametxt" runat="server" MaxLength="100" CssClass="input"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" Display="None" runat="server"
            ErrorMessage="Director First Name is required." ControlToValidate="DirectorfirstNametxt"></asp:RequiredFieldValidator>
              </td>
        </tr>

</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="isDirector" EventName="SelectedIndexChanged" />
</Triggers>

I am trying to change the CSS CLASS of TR ID = "test"

4
  • I assume that this is a CheckedChanged-Event handler from a CheckBox inside of a HTML-TableRow. You could try to cast the sender to your CheckBox and it's ParentParent-Control to HtmlTableRow. Commented Jun 29, 2011 at 13:29
  • ...therefore you need to make the tr's runat=server. Commented Jun 29, 2011 at 13:36
  • They are, but I still dont know how I can change the CSSCLASS of the TR in CheckedChanged-Event handler from a CheckBox Commented Jun 29, 2011 at 13:37
  • Can you please post complete code, so that we can have better understadining and then we were able to help you. Commented Jun 29, 2011 at 13:40

2 Answers 2

4

Assuming you have your Checkboxes inside of a HTML-TableRow and you want to set the CSS-Class of the TR in the CheckedChanged-Event:

This is an example(note that the TR's have a runat="server"-tag):

<table>
    <tr ID="TR1" runat="server">
        <td>
            <asp:CheckBox ID="CheckBox1" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
        </td>
    </tr>
     <tr ID="TR2" runat="server">
        <td>
            <asp:CheckBox ID="CheckBox2" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
        </td>
    </tr>
     <tr ID="test" runat="server">
        <td>
            <asp:CheckBox ID="CheckBox3" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
        </td>
    </tr>
   </table>

and this is the codebehind:

protected void isDirector_CheckedChanged(object sender, EventArgs e)
{
    //var row = (HtmlTableRow)((CheckBox)sender).Parent.Parent;
    test.Attributes("class") = "CssClass";
}

Edit: if your tr's are runat="server" and they have unique ID's, you can access them directly

Sign up to request clarification or add additional context in comments.

2 Comments

I need to reference this TR by ID in the behind
@StevieB: if they are runat=server and have unique ID's you can access the "test"-tr directly via it's ID (see my edited answer).
0

What kind of control is isDirector_CheckChanged tied to - a checkbox?

As the error says, EventArgs is the type of event you're expecting and it doesn't have an 'Item' property. Maybe you're thinking of GridView, Repeater, or other 'item-like' controls?

I'm guessing you're trying to handle the changed event of a checkbox you've put in a repeating/table control. If so, you'll need to handle a Selected or similar event for the repeater that DOES use an EventArgs-derived type with an Item property.

1 Comment

Its a checkbox yeah, how can I edit the cssClass of a TR when onchange checkbox happens

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.