Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested repeater tutorial in vb.net

Status
Not open for further replies.

orangelight

Technical User
Feb 17, 2005
20
GB
Hi
can some one give me an example or know of an example of a nested repeater
thanks
Hesh
 
Code:
<asp:Repeater id="TopRepeater" runat="server" 
DataSourceId="MyDataSource">
   <HeaderTemplate>...</HeaderTemplate>
   <ItemTemplate>
      //standard controls and stuff
      <asp:Repeater 
           id="NestedRepeater" 
           runat="server" 
           DataSource='<%#Eval("MyEnumeratedProperty") %>'>
         <HeaderTemplate>...</HeaderTemplate>
         <ItemTemplate>...</ItemTemplate>
         <FooterTemplate>...</FooterTemplate>
      <asp:Repeater>
   <ItemTemplate>
   <FooterTemplate>...</FooterTemplate>
</asp:Repeater>

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I have done this function


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create the connection and DataAdapter for the Authors table.

Dim connstring As String
Dim cnn As SqlConnection
connstring = ConfigurationSettings.AppSettings("ConnectionString")


cnn = New SqlConnection(connstring)
Dim cmd1 As New SqlDataAdapter("select * from tble_content", cnn)

''Create and fill the DataSet.
Dim ds As New DataSet()
cmd1.Fill(ds, "content_name")

'Create a second DataAdapter for the Titles table.
Dim cmd2 As New SqlDataAdapter("select content_subnav, content_name, content_no_id from view_aspx_subnav", cnn)
cmd2.Fill(ds, "content_names")

'Create the relation bewtween the Authors and Titles tables.
ds.Relations.Add("myrelation", ds.Tables("tble_content").Columns("Content_no_id"), ds.Tables("view_aspx_subnav").Columns("content_subnav"))

'Bind the Authors table to the parent Repeater control, and call DataBind.
parent1.DataSource = ds.Tables("content_name")
Page.DataBind()
cnn.Close()
End Sub
</script>

but I am getting thie following error
Object reference not set to an instance of an object.
can anyone help
thanks in advance
Hesh
 
what line of code throws the error?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
hi
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Line 42:
ds.Relations.Add("myrelation", ds.Tables("tble_content").Columns("Content_no_id"), ds.Tables("view_aspx_subnav").Columns("content_subnav"))



hope you can help
thanks
Hesh
 
datatables are disconnected from the database. so once your in a datatable where the data came from is irrelvant. that's the command/connection objects purpose.

so when building relations in a dataset the database schema is not applicable. instead you need to use the dataset schema to create the relationship.

the table names in the dataset are different than the table names in the db, so use the dataset table names for the relationships. column names will be the same, because there are no mapping changes.

table/column/relationship names are case sensative.


i tweaked your code below.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   'Create the connection and DataAdapter for the Authors table.
               
   Dim connstring As String
   Dim cnn As SqlConnection
   connstring = ConfigurationSettings.AppSettings("ConnectionString")
               
              
   cnn = New SqlConnection(connstring)
   Dim cmd1 As New SqlDataAdapter("select [list fields here not *. it's good practice] from tble_content", cnn)

   ''Create and fill the DataSet.
   Dim ds As New DataSet()
   cmd1.Fill(ds, "content_name")

   'Create a second DataAdapter for the Titles table.
   Dim cmd2 As New SqlDataAdapter("select content_subnav, content_name, content_no_id from view_aspx_subnav", cnn)
   cmd2.Fill(ds, "content_names")

   ''close connection
   cnn.Close()

   'Create the relation bewtween the Authors and Titles tables.
   ds.Relations.Add("myrelation", ds.Tables("content_name").Columns("content_no_id"), ds.Tables("content_names").Columns("content_no_id"))

   'Bind the Authors table to the parent Repeater control, and call DataBind.
   parent1.DataSource = ds
   parent1.DataMember = ds.Tables("content_name")
   parent1.DataBind()
End Sub

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks Jason
But i am getting an error on this line

parent1.DataMember = ds.Tables("content_name")

error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30311: Value of type 'System.Data.DataTable' cannot be converted to 'String'.

thanks hesh
 
ds.Tables("content_name").TableName

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top