GridView nested in DataList and SelectedIndexChanged event of both

Last post 05-14-2008 1:08 PM by gstoy. 1 replies.

Sort Posts:

  • GridView nested in DataList and SelectedIndexChanged event of both

    05-14-2008, 11:03 AM
    • Loading...
    • gstoy
    • Joined on 05-14-2008, 10:46 AM
    • Posts 3

    I have a GridView nested in DataList. Upon binding, the DataList generates a bunch of line items, each containing an instance of the GridView. Here's a code snipped:

    <asp:DataList ID="DataList1" runat="server" DataSourceID="CaseManagersDataSource" OnItemCommand="DataList1_ItemCommand">

    <ItemTemplate>

    <asp:GridView ID="gridViewWorkQueue" runat="server" DataSource='<%# Eval("WQCases") %>' OnSelectedIndexChanged="gridViewWorkQueue_SelectedIndexChanged">

    <Columns>

    <asp:CommandField ButtonType="Image" SelectImageUrl="~/Images/Icons/info_16.png" ShowSelectButton="True" CausesValidation="False" />

    <asp:BoundField DataField="CaseGUID" HeaderText="CaseGUID" SortExpression="CaseGUID" Visible="False" />

    <asp:BoundField DataField="BCDHSCaseNumber" HeaderText="Case #" SortExpression="BCDHSCaseNumber" NullDisplayText="&lt;i&gt;(missing Msg. 23-Q)&lt;/i&gt;" />

    </Columns>

    </asp:GridView>

    </ItemTemplate>

    </asp:DataList>

    As you can see CommandField in the GridView is set to fire the "select" command - works as expected - gridViewWorkQueue_SelectedIndexChanged event handler is envoked on the post back.

    My problem is that the "parent" DataList SelectedItem is null and SelectedIndex is -1.

    I assume that's by design, since the "select" command initiated from the nested GridView.

    My question is how to make the selection of a DataGrid row to also select the DataList row that contains that DataGrid.

    I was thinking about using GridView's Parent...

    Thanks!

  • Re: GridView nested in DataList and SelectedIndexChanged event of both

    05-14-2008, 1:08 PM
    Answer
    • Loading...
    • gstoy
    • Joined on 05-14-2008, 10:46 AM
    • Posts 3

    Resolution:

    Just want to say that I was able to determine the selected index of the DataList that contaiuned the clicked GridView by using ((GridView)sender).Parent.

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter