Results 1 to 2 of 2

Thread: Repeater and DataView

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    43

    Repeater and DataView

    Good morning all,

    How will I display Dataview's datarows as Parent and child format in the repeater?

    Cheers,
    Dummy
    ***learning everyday ***

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366

    Re: Repeater and DataView

    I usually use a nested repeater:
    PHP Code:
    public class YourPage Page
    {
      private 
    DataTable _parentsAndChildren;
      protected 
    Repeater rptrParents;
      protected 
    override void OnLoad(System.EventArgs e)
      {
        if(!
    Page.IsPostBackbindData();
      }
      private 
    void bindData()
      {
        
    //code to fill up _parentsAndChildren with data goes here.
        
    DataView parents = new DataView(_parentsAndChildren);
        
    parents.RowFilter "ParentID = ChildID";
        
    rptrParents.DataSource parents;
        
    rptrParents.DataBind();
      }
      protected 
    DataView GetChildren(object dataItem)
      {
        
    DataView children null;
        
    DataRowView parentRow dataItem as DataRowView;
        if(
    parentRow != null)
        {
          
    string rowFilter "ParentID<>ChildID and ParentID=" 
            
    parentRow["ParentID"].ToString();
          
    children = new DataView(_parentsAndChildren);
          
    children.RowFilter rowFilter;
        }
        return 
    children;
      }

    the repeater on the aspx page would look something like this:
    Code:
    <asp:Repeater ID="rptrParents" Runat="server">
      <HeaderTemplate>
        <table>
          <tr>
            <td>Name</td>
          </tr>
      </HeaderTemplate>
      <ItemTemplate>
        <tr>
          <td>
            <%# DataBinder.Eval(Container.DataItem, "Name") %>
          </td>
        </tr>
        <!-- Now get the children for the current parent -->
        <asp:Repeater ID="rptrChildren" Runat="server" 
          DataSource='<%# GetChildren(Container.DataItem) %>'>
          <ItemTemplate>
            <tr>
              <td>
                <%# DataBinder.Eval(Container.DataItem, "Name") %>
              </td>
            </tr>
          </ItemTemplate>
        </asp:Repeater>
      </ItemTemplate>
      <FooterTemplate>
        </table>
      </FooterTemplate>
    </asp:Repeater>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width