Question on accessing a nested GridViews Events

Discussion in 'ASP .Net' started by Scooby Dog, Apr 15, 2010.

  1. Scooby Dog

    Scooby Dog Guest

    Could somone please help:




    how do you access a GridView's events like SelectedIndexChanged when it's
    nested within another grid. the inner grid is populated via the outer grids
    rowdatabound.

    Here is an example of what my grids look like:
    http://www.giswiz.com/nested_gridview_dropdown/





    I have a page with a nested Gridview control within an outer Gridview
    (Master/Child). ie: GridView1 -> GridView2. I have the inner grid being
    populated via the outer grids RowDatabound event. The goal of the whole
    thing is to show a customer record in the outer grid and then when a user
    clicks on the expand button of the outer row an inner grid drops down
    showing all the related Item records. I have the grids populating and
    displaying correctly but I need to have access to the inner grid's events
    like SelectedIndexChanged and Sorting to add required functionality to the
    page. I have tried hard coding events to the inner grid like

    OnSelectedIndexChanged="gvItems_SelectedIndexChanged" and then adding the
    code behind for that sub but I get an error stating that it's not ASP.net
    Default.





    Here is the code from the outer grids gvInqStatus_RowDataBound() which binds
    the inner grid.


    If e.Row.RowType = DataControlRowType.DataRow Then
    Dim gv As GridView = e.Row.FindControl("gvItems")


    Dim ID As Integer = CType(e.Row.Cells(1).Text, Integer)
    Dim db As New PurchInquiryDataContext
    Dim items = From i In db.Items Where i.FK_InqID = ID _
    Select New With {.ItemID = i.ItemID, .Quantity =
    i.Qty, .Description = i.Description, _
    .Grade = i.Grade, .Feet =
    i.Feet, .Inches = i.Inches}

    gv.DataSource = items
    gv.DataBind()

    End If




    Here is the html for the gridviews




    <asp:GridView ID="gvInqStatus" AutoGenerateColumns="False"
    DataKeyNames="inqID" AllowSorting="True"
    BorderWidth="0" runat="server"
    BorderStyle="None" Width="99%" CellPadding="2"
    AllowPaging="true" PageSize="10"
    BorderColor="White" >
    <Columns>

    <asp:TemplateField>
    <ItemTemplate>
    <a
    href="javascript:switchViews('div<%# Eval("inqID") %>', 'one');">
    <img id="imgdiv<%# Eval("inqID")
    %>" alt="Click to show/hide orders" border="0"
    src="App_Themes/images/expand_button_white.jpg"
    />
    </a>
    </ItemTemplate>
    <AlternatingItemTemplate>
    <a
    href="javascript:switchViews('div<%# Eval("inqID") %>', 'alt');">
    <img id="imgdiv<%# Eval("inqID")
    %>" alt="Click to show/hide orders" border="0"
    src="App_Themes/images/expand_button_white.jpg"
    />
    </a>
    </AlternatingItemTemplate>
    </asp:TemplateField>

    <asp:BoundField DataField="inqID"
    HeaderText="Inquiry Number" SortExpression="InqID"
    Visible="true"><ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField DataField="CustNum"
    HeaderText="Customer Number" SortExpression="CustNum">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField DataField="CustName"
    HeaderText="Customer Name" SortExpression="CustName">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField DataField="DistrictCode"
    HeaderText="District" SortExpression="DistrictCode">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField DataField="SalesNum"
    HeaderText="Sales Number" SortExpression="SalesNum">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField DataField="QuoteDate"
    HeaderText="Quote Date" DataFormatString="{0:d}"
    SortExpression="QuoteDate">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField DataField="Status"
    HeaderText="Quote Status" SortExpression="Status">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:TemplateField>
    <ItemTemplate>
    </td></tr>
    <tr>
    <td colspan="100%">
    <div id="div<%#
    Eval("InqID") %>" style="display: none; position: relative;
    left: 25px;">
    <asp:GridView
    ID="gvItems" runat="server" Width="80%" AutoGenerateColumns="false"
    DataKeyNames="ItemID"
    EmptyDataText="No items for this customer." HeaderStyle-BackColor="#D6DDE9"
    AllowSorting="True">
    <Columns>
    <asp:BoundField
    DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField
    DataField="Description" HeaderText="Description"/>
    <asp:BoundField
    DataField="Grade" HeaderText="Grade">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField
    DataField="Feet" HeaderText="Feet">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:BoundField
    DataField="Inches" HeaderText="Inches">
    <ItemStyle
    HorizontalAlign="Center"></ItemStyle></asp:BoundField>
    <asp:CommandField
    ShowSelectButton="true" HeaderText="View Detail"
    SelectImageUrl="App_Themes/images/grid-view.gif"
    ButtonType="Image"
    SelectText="View"
    ItemStyle-HorizontalAlign="Center"/>
    </Columns>
    <RowStyle
    HorizontalAlign="Left" CssClass="row1" />
    <HeaderStyle
    CssClass="grid-header" HorizontalAlign="Left" />
    </asp:GridView>
    </div>
    </td>
    </tr>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    <RowStyle HorizontalAlign="Left" CssClass="row1"
    />
    <HeaderStyle CssClass="grid-header"
    HorizontalAlign="Left" />
    <EmptyDataTemplate>
    <asp:Label ID="Label10" runat="server"
    Text="Label">There are no Purchase Inquirys Entered</asp:Label>
    </EmptyDataTemplate>
    </asp:GridView>
     
    Scooby Dog, Apr 15, 2010
    #1
    1. Advertising

  2. Scooby Dog

    Mr. Arnold Guest

    Scooby Dog wrote:
    > Could somone please help:
    >
    >
    >
    >
    > how do you access a GridView's events like SelectedIndexChanged when
    > it's nested within another grid. the inner grid is populated via the
    > outer grids rowdatabound.
    >
    > Here is an example of what my grids look like:
    > http://www.giswiz.com/nested_gridview_dropdown/
    >
    >
    >
    >
    >
    > I have a page with a nested Gridview control within an outer
    > Gridview (Master/Child). ie: GridView1 -> GridView2. I have the inner
    > grid being populated via the outer grids RowDatabound event. The goal
    > of the whole thing is to show a customer record in the outer grid and
    > then when a user clicks on the expand button of the outer row an inner
    > grid drops down showing all the related Item records. I have the grids
    > populating and displaying correctly but I need to have access to the
    > inner grid's events like SelectedIndexChanged and Sorting to add
    > required functionality to the page. I have tried hard coding events
    > to the inner grid like


    You may have to have both Gridviews point to the same
    OnSelectedIndexChanged()

    void GridView_SelectedIndexChanged(Object sender, GridViewSelectEventArgs e)
    {
    //based on what GridView is the 'sender' GridView1 or GridView2

    var gridview = (GridView)sender; // cast it

    if(gridview.ID == "GridView1"
    {
    // dosomething
    }
    else
    {
    // dosomething for GV2
    }


    }
     
    Mr. Arnold, Apr 15, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    4,782
  2. Roy
    Replies:
    1
    Views:
    3,824
  3. Chris

    Nested Gridviews

    Chris, Apr 1, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    444
    Chris
    Apr 1, 2007
  4. Mr Nobody

    Nested GridViews In UserControls.

    Mr Nobody, Jul 25, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    317
    Lucas Hernandez
    Jul 25, 2008
  5. katmagic

    Gridviews and Nested Gridview

    katmagic, Jan 17, 2009, in forum: ASP .Net
    Replies:
    0
    Views:
    327
    katmagic
    Jan 17, 2009
Loading...

Share This Page