Changing the cssclass for a <tr> using vb.net

1.6k views Asked by At

I have this and I want to hide rows dynamically using vb.net codebehind. I am using VS2010.

This is my table:

<table>
    <tr id="FromDateRow">
        <td><asp:Label ID="FromDateLabel" runat="server">From date:</asp:Label></td>
        <td>
            <input type="text" id="txtFromDateF" class="needs-datepicker" />
            <asp:TextBox id="txtFromDate" CssClass="hidden" runat="server" />
        </td>
    </tr>
    <tr id="ToDateRow">
        <td><asp:Label ID="ToDateLabel" runat="server">To date:</asp:Label></td>
        <td>
            <input type="text" id="txtToDateF" class="needs-datepicker" />
            <asp:TextBox id="txtToDate" CssClass="hidden" runat="server" />
        </td>
    </tr>
    <tr>
        <td><asp:Label ID="CustomerCodeLabel" runat="server">Customer Code</asp:Label>:</td>
        <td><asp:DropDownList ID="CustomerCodeDropDownList" runat="server" AutoPostBack="False" /></td>
    </tr>
    <tr>
        <td><asp:Label ID="CINumberLabel" runat="server">CI Number</asp:Label>:</td>
        <td><asp:TextBox ID="CINumberTextBox" runat="server" /></td>
    </tr>
</table>

Now I want to do something like this:

Select Case value
            Case DisplayDates.FromDate
                ToDateRow.CssClass = "hidden"
                FromDateRow.CssClass = ""
            Case DisplayDates.ToAndFromDate
                ToDateRow.CssClass = ""
                FromDateRow.CssClass = ""
            Case Else
                ToDateRow.CssClass = "hidden"
                FromDateRow.CssClass = "hidden"
        End Select

For some reason I cannot access the ToDateRow and the FromDateRow from my codebehind.

3

There are 3 answers

0
Bart Schelkens On BEST ANSWER

Ok I solved it. By adding the runat="server" i was able to access the row. And then I found the "visible"-property. Now it works just fine. Thx for the help

1
4b0 On

You must have

runat="server

tag in table and tr to access from code behind.

After comment :

ToDateRow.Attributes("class") = "CssClass";
0
NicoE On

The objects you are trying to reference in codebehind (the relevant tr elements) needs to be defined as runat="server"

If CssClass is not a known property for the object instance try using the following:

rowObject.Attributes.Add("class", "hidden");