A sample code to Add two DataTables in a datagrid using bound columns

A sample code to Add two DataTables in a datagrid using bound columns? Create a main Page (Drag and drop Datagrid on the design view ) ? Change the Datagrid Autogenerate Property = false) ? The demonstartion creates a Datagrid Bound Columns dynamically and add two datatables to one datagrid[bold]Step 1: main.aspx[/bold][code]

Contributed by
Rating: 3 stars3 stars3 stars3 stars3 stars / 18
June 01, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
A sample code to Add two DataTables in a datagrid using bound columns? Create a main Page (Drag and drop Datagrid on the design view ) ? Change the Datagrid Autogenerate Property = false) ? The demonstartion creates a Datagrid Bound Columns dynamically and add two datatables to one datagrid[bold]Step 1: main.aspx[/bold]


<asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 278px; POSITION: absolute; TOP: 81px" runat="server" AutoGenerateColumns="false"></asp:DataGrid>

[bold]Step 2: main.aspx.vb [/bold]


Try

Dim mycn As New System.Data.SQLClient.SqlConnection("server=localhost;uid=sa;password=;database=northwind;")

Dim myda As New System.Data.SQLClient.SqlDataAdapter("Select productid,categoryid,productname from Products "mycn)

Dim myda1 As New System.Data.SQLClient.SqlDataAdapter("Select categoryid from Categories "mycn)

Dim ds As New System.Data.DataSet()

myda.Fill(ds"Products")

myda1.Fill(ds"Categories")

Dim objbc As BoundColumn

Dim dc 
As DataColumn

Dim dt 
As DataTable

For Each dt In ds.Tables

    
For Each dc In dt.Columns

        objbc 
= New BoundColumn()

        
objbc.HeaderText dc.ColumnName

        objbc
.DataField dc.ColumnName

        DataGrid1
.Columns.Add(objbc)

    
Next

Next

DataGrid1
.DataSource ds.Tables(0

DataGrid1.DataBind()

Catch 
ex As Exception

Response
.Write(ex.Message ex.StackTrace)

End Try

blog comments powered by Disqus
ASP.NET CODE ARTICLES

- How to Use the ListBox Control in ASP.NET 2.0
- How to Load XML Documents in ASP.NET 2.0
- DataGrid Code
- ASP.NET Guestbook
- User Controls and Client Side Scripting
- ASP.NET Programming with Microsoft's AS...
- ASP.NET Basics (part 3): Hard Choices
- ASP.NET Basics (part 2): Not My Type
- ASP.NET Basics (part 1): Nothing But .Net
- Directory Tree Browser
- How to get the confirmation of Yes/No from a...
- Complete example using custom errors and wri...
- Paging Certain # records per page .NET style
- General Methods of formatting and Subtractin...
- .NET LinkButton web control

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials