Question on accessing a nested GridViews Events

S

Scooby Dog

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>
 
M

Mr. Arnold

Scooby said:
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
}


}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top