Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

a colleague asked me if you could insert a datagrid inside a datarepeater, i wasnt sure at that time so i tried searching but was unable to get any info on it, so i tried messin with the repeater events diggin inside watch values

 

heres what i came up with

 

on the page i have the repeater with a datagrid within itemtemplate

   <asp:Repeater ID="Repeater1" runat="server">
       <HeaderTemplate>
           <table>
       </HeaderTemplate>

       <ItemTemplate>
       <tr>
           <td>
           TABLE 1<br />
               <%#DataBinder.Eval(Container.DataItem, "ID")%>           
               <%#DataBinder.Eval(Container.DataItem, "NAME")%>
           </td>
           <td>
           TABLE 2
               <asp:DataGrid ID="datagrid1" runat="server">                
               </asp:DataGrid>
           </td>            
       </tr>
       <tr>
           <td colspan="2">
           <hr />
           </td>
       </tr>
       </ItemTemplate>

       <FooterTemplate>
           </table>
       </FooterTemplate>
   </asp:Repeater>

 

in my code behind (took off the sqlclass, just the usual anyway)

Protected Sub form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles form1.Load

       Dim dt1 As New DataTable("TABLE1")
       Dim query As String = ""

       query = "SELECT TOP 10 * ID, [NAME] FROM TABLE1"
       dt1 = sqlClass.execQuery(query, dt1.TableName)  ' returns datatable

       Repeater1.DataSource = dt1
       Repeater1.DataBind()
End Sub

Protected Sub Repeater1_ItemCreated(ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) _
    Handles Repeater1.ItemCreated

       Dim dt2 As New DataTable("TABLE2")
       Dim query As String = ""

       Try
           ' itemtemplate (can also be checked with ItemType)
           Dim drv As DataRowView
           drv = e.Item.DataItem

           query = "SELECT Something FROM TABLE2 where ID = '" & drv.Row.Item("ID") & "'"
           dt2 = sqlClass.execQuery(query, dt2.TableName)

           Dim datagrid1 As DataGrid = DirectCast(e.Item.FindControl("datagrid1"), DataGrid)

           datagrid1.DataSource = dt2
           datagrid1.DataBind()
       Catch
           ' headertemplate or footertemplate (do nothing)
       End Try
End Sub

 

is there another way, just curious?

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...