views:

1182

answers:

6

I've got a small web form with 2 radio buttons, call them PickFromList and EnterValue. When PickFromList is checked I want to show a GridView that I've configured to bind to an ObjectDataSource. When EnterValue is checked I want the GridView to disappear.

This form is laid out using a table and want to hide/show the appropriate rows based on appropriate data and user input.

Unfortunately the GridView doesn't bind when the trPickFromList2 row specifies the id and the runat="server" attributes. If I remove id and runat="server" from the trPickFromList2 row it binds successfully.

Any ideas?

<table id="tblOptions" runat="server">
    <tr id="trPickFromList1" runat="server">
        <td>
            <asp:RadioButton ID="rbFromList" runat="server" GroupName="Selection" 
                Text="Get Data From Existing Item" AutoPostBack="True" 
                oncheckedchanged="rbromList_CheckedChanged" />
        </td>
    </tr>
    <tr id="trPickFromList2" runat="server">
        <td style="padding-left:20px">
            <asp:GridView ID="gvList" runat="server" AutoGenerateColumns="False" 
                DataSourceID="odsList" Width="400px" onrowdatabound="gvList_RowDataBound">
                <Columns>
                    ...
                </Columns>
            </asp:GridView>
        </td>
    </tr>
    <tr id="trEnterValue1" runat="server">
        <td>
            <asp:RadioButton ID="rbEnterValue" runat="server" GroupName="Selection" 
                            Text="Create a New Item"
                            AutoPostBack="True" 
                            oncheckedchanged="rbEntered_CheckedChanged" />
        ...
A: 

hmm.. not quite sure but something which has got me a few times is have the AutoWireEvents set to false, its at the top in the <% page /%> section. sorry if it's no help, but something annoying and insignificant like that is prob the problem.

Joe
A: 

If the AutoWireEvents answer Joe suggested is not the issue, you could also try removing the runat=server from the tr tags, and instead wrap them with placeholders and use the placeholders to control visibility. (Note, don't use panels, as it will result in invalid html)

wulimaster
+1  A: 

Why dont you just show/hide the TRs with javascript? That way you won't have this problem and you'll have a much more responsive UI.

With jQuery:

$('.classOnShowRadioButton').click(function(){ $('.trToShow').show(); $('.trToHide').hide(); });

then obviously do the reverse for the other radio button.

Andrew Bullock
That's a good suggestion. There's no good reason, just that we're not a big JavaScript shop. There are some additional problems, such as validation errors on postback that would have to be handled too.
marc
A: 

I noticed the same behavior with a FormView inside a TR tag with runat="server"

devio
A: 

Any particular reason you're using a table for layout? Try taking all your controls out of the table, and make the radio buttons just make the actual GridView visible/invisible.

sliderhouserules
Just for alignment purposes - 20px in to subordinate the grid to the radio button.
marc
The reason I ask is because you're turning your TR into a server object in order to show/hide it. But your GridView is already a server object and you are able to show/hide it by itself. The only caveat to doing this is the TR will still be rendered (empty). Without the table it's cleaner.
sliderhouserules
+1  A: 

I ended up implementing Wilco Bauwer's RowSelectorField control to solve this problem. It's not a perfect solution in that the control surfaces the the selected row's index value rather than the selected data key value(s); however, it worked out well.

marc