Master/Detail record...how to display in data grid

Discussion in 'ASP .Net Web Controls' started by PatLaf, Feb 5, 2004.

  1. PatLaf

    PatLaf Guest

    Hello to all...I have two tables that I retrieve on page load. I bind the master table to the datagrid and I have added the column to display the detail record but I need help with the datagrid I think. The list in the datagrid exceeds the page length...I can't use paging I have to show them all it is for our auditors, I would like to be able to display the list of checkboxes displaying the detail records directly underneath the row where the user clicked the show details button. I have an example from Dino Espositos book Building Web solutions with asp.net and ado.net but unfortunately I am new to vb.net and the example is in c# which I have even less experience with. Does anyone have a sample or know where I can look at something close to what I want to do?

    Thanks in advance,

    Pat
     
    PatLaf, Feb 5, 2004
    #1
    1. Advertising

  2. Hi Pat,

    Thank you for posting in the community!

    Based on my understanding, you use datagrid to display Master/Details
    datatables. You use an extra column to show the details records.

    ======================================================
    I have writen a sample project for this issue, in it, I use SqlServer's
    default datatable "Categories" and "Products" in "Northwind" as datasouce.

    Based on my research, I use an extra column to include an invisible
    datagrid to show the details table. Html view like this:

    <asp:datagrid id="Master" style="Z-INDEX: 101; LEFT: 48px; POSITION:
    absolute; TOP: 24px" runat="server"
    Width="480px" Height="304px" AutoGenerateColumns="False">
    <Columns>
    <asp:BoundColumn DataField="CategoryID"></asp:BoundColumn>
    <asp:BoundColumn DataField="CategoryName"></asp:BoundColumn>
    <asp:BoundColumn DataField="Description"></asp:BoundColumn>
    <asp:ButtonColumn Text="Show Details"
    ButtonType="PushButton"></asp:ButtonColumn>
    <asp:TemplateColumn Visible="False">
    <ItemTemplate>
    <asp:DataGrid Runat="server" ID="details"
    Visible="False"></asp:DataGrid>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>



    Then, when user click the "Show details" button, I en-visible that column
    and the details datagrid, code below:

    Dim ds As Dataset1
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    getsource()
    masterdatabind()
    End If
    End Sub

    Public Sub getsource()
    Dim adapter1 As SqlDataAdapter = New SqlDataAdapter("select * from
    Products", "server=localhost;database=Northwind;uid=sa;pwd=")
    Dim adapter2 As SqlDataAdapter = New SqlDataAdapter("select * from
    Categories", "server=localhost;database=Northwind;uid=sa;pwd=")
    ds = New Dataset1
    adapter2.Fill(ds, "Categories")
    adapter1.Fill(ds, "Products")
    End Sub

    Public Sub masterdatabind()
    Master.DataSource = ds.Categories
    Master.DataBind()
    End Sub

    Private Sub Master_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    Master.ItemDataBound
    Dim dgi As DataGridItem = e.Item
    If dgi.ItemType = ListItemType.Item Or dgi.ItemType =
    ListItemType.AlternatingItem Then
    Dim c As Control
    For Each c In dgi.Cells(4).Controls
    If TypeOf (c) Is System.Web.UI.WebControls.DataGrid Then
    Dim id As Int32 = Int32.Parse(dgi.Cells(0).Text)
    Dim dg As DataGrid = CType(c, DataGrid)
    Dim dr As DataRow()
    dr = ds.Products.Select("CategoryID=" & id)
    dg.DataSource = dr
    dg.DataBind()
    End If
    Next
    End If
    End Sub

    Private Sub Master_ItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
    Master.ItemCommand
    If CType(e.CommandSource, Button).Text = "Show Details" Then
    Master.Columns(4).Visible = True
    Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
    Dim c As Control
    For Each c In dgi.Cells(4).Controls
    c.Visible = True
    Next
    CType(e.CommandSource, Button).Text = "Hide Details"
    Else
    Master.Columns(4).Visible = False
    Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
    Dim c As Control
    For Each c In dgi.Cells(4).Controls
    c.Visible = False
    Next
    CType(e.CommandSource, Button).Text = "Show Details"
    End If

    The code works well on my machine

    =============================================================
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.
    Have a nice day!!

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Feb 6, 2004
    #2
    1. Advertising

  3. Jeff,

    When I run the sample and click on Show Details I don't see the details.
    I get two colomns that are titled Row Errors and Has Errors
    respectively. The HasErrors column is false all the way done but there
    is nothing in the other column. Do you know why it's not displaying the
    details for me?

    Thanks in advance,
    PatLaf

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Patrick Laferriere, Feb 6, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ruca

    Master / Detail Grid

    ruca, Apr 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,962
  2. asmj
    Replies:
    0
    Views:
    511
  3. Savvoulidis Iordanis

    Creating XML Master/detail in one line per record.

    Savvoulidis Iordanis, Nov 29, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,710
    Christophe Lephay
    Nov 29, 2008
  4. Arun Kumar Menon

    Master Detail detail

    Arun Kumar Menon, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    205
    Arun Kumar Menon
    Aug 6, 2003
  5. Frederik Borg

    ASp.net data binding: Master-detail-detail

    Frederik Borg, Jun 9, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    365
    Frederik Borg
    Jun 9, 2006
Loading...

Share This Page