Nested detailsview

J

James Page

Hi all
I have a nested detailsView in a gridView.
What I’m trying to do is display values derived from the row in the gridview
and pass the row id to the detailsview to produce something like:

Gridview item 1
Detailsviewitem1
Detailsviewitem2
Detailsviewitem3
GridviewItem 2
Detailsviewitem1
Detailsviewitem2
Etc...

The data (SQL) is stored like so:
GridView data

Id
Name

DetailsView Data
Id
GridviewId
Text

What i need to do is pass the gridviewRow id to the detailsview and display
matching data without the need for using selected row.
I’m sure i need a for each loop but how do I retrieve the gridview row id
and pass this variable to the datasource for the detailsview and show only
data where the gridview id matches the gridviewId in the detailsview table?

Thanks
 
J

James Page

Hi again

I've managed to sort out how to databind the nested listView (changed from
detailsView) but how do I reference the label in the list view?

Aspx page:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Eval("name") %>'></asp:Label>

<asp:Label ID="Label3" runat="server" Text='<%#
Eval("id") %>' Visible="False"></asp:Label>
<div>

<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:Label ID="Label4" runat="server"
Text='<%# Eval("test") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
</div>
</ItemTemplate>
</asp:TemplateField>


</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [BizNames] ORDER BY [name]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

Code:

Imports System.Linq

Partial Class _Default
Inherits System.Web.UI.Page


Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GridView1.DataBound
Dim x As New DataClassesDataContext
For Each row As GridViewRow In GridView1.Rows
Dim s As Label = row.FindControl("Label3")
Dim txt As String = s.Text

Dim dl As DataList = row.FindControl("DataList1")

'Dim lbl As Label = dl.FindControl("Label4")
'lbl.BackColor = Drawing.Color.Aquamarine

'This is where I'm getting the null reference warning

dl.DataSource = x.StoredProcedure1(txt)
dl.DataBind()

Next
End Sub
End Class

Hope someone can advise

Thanks
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top