[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

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

PatLaf

2/5/2004 4:01:00 PM

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
7 Answers

v-jetan

2/6/2004 8:38:00 AM

0


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.

v-jetan

2/6/2004 9:03:00 AM

0


Hi Pat,

Ho, For your datagrid extends the page length concern, I think you can use
scrollable div to resolve it.

For more information, please refer to:
http://www.dotnetjohn.com/articles/articl...
http://www.dnzone.com/ShowDetail.asp?...

Hope it helps,

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.

PatLaf

2/6/2004 3:31:00 PM

0

Jeff,
Thanks so much. That is exactly what I was looking for. We must be
using different versions of VS.NET as I had to alter the sample just a
little. I had to change the ds.Categories to ds.tables("Categories") and
all worked well. You rescued me from a 3 day nightmare.

Most appreciated

Pat Laf



*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

PatLaf

2/6/2004 7:55:00 PM

0


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.develop... ***
Don't just participate in USENET...get rewarded for it!

v-jetan

2/8/2004 10:03:00 AM

0


Hi Patrick,

Thanks very much for your feedback.

I am glad my reply helps you.

I used Visual Studio.Net 2003. Actually, I used the Typed DataSet in my
sample application, and its syntax is ds.Categories etc. Sorry for not
inform you.

Anyway, you figured it out.

If you have any further concern, please feel free to tell me, I will work
with you.

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.

PatLaf

2/9/2004 1:04:00 PM

0

Jeff,
I'm not sure why but when I run the app and click the details I get the
second datagrid with two columns. The first title is Row Errors and the
Second is Has Errors. The second column all states false but no details.
Could this be because of me not using a typed dataset? Or is there a
gremlin in my code?


Thanks in advance,
PatLaf


*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

v-jetan

2/10/2004 5:41:00 AM

0


Hi Patrick,

I found you have posted a new post for this issue.

I will follow up you in your new post, thanks.

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.