Tuesday, October 21, 2014

how to create a table dynamically and bind to gridview in vb.net

Posted by Unknown  |  No comments


 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  

 how to create a table dynamically and bind to gridview in vb.net  
 -----------------------------------------------------------------:  
 step1):  
 -------  
  <html xmlns="http://www.w3.org/1999/xhtml">  
 <head runat="server">  
 <title>Dynamically create datatable and bind data to it in asp.net</title>  
 </head>  
 <body>  
 <form id="form1" runat="server">  
 <div>  
 <asp:GridView ID="gvDetails" runat="server">  
 </asp:GridView>  
 </div>  
 </form>  
 </body>  
 </html>  
 step 2):  
 -------  
  Imports System  
 Imports System.Data  
 Partial Class Default  
 Inherits System.Web.UI.Page  
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load  
 If Not IsPostBack Then  
 BindGridviewData()  
 End If  
 End Sub  
 ' Dynamically create & bind data to datatable and bind datatable to gridview  
 Protected Sub BindGridviewData()  
 Dim dt As New DataTable()  
 dt.Columns.Add("UserId", GetType(Int32))  
 dt.Columns.Add("UserName", GetType(String))  
 dt.Columns.Add("Education", GetType(String))  
 dt.Columns.Add("Location", GetType(String))  
 Dim dtrow As DataRow = dt.NewRow()  
 ' Create New Row  
 dtrow("UserId") = 1  
 'Bind Data to Columns  
 dtrow("UserName") = "gnani"  
 dtrow("Education") = "B.Tech"  
 dtrow("Location") = "prakasam"  
 dt.Rows.Add(dtrow)  
 dtrow = dt.NewRow()  
 ' Create New Row  
 dtrow("UserId") = 2  
 'Bind Data to Columns  
 dtrow("UserName") = "gopal"  
 dtrow("Education") = "M.tech"  
 dtrow("Location") = "srikakulam"  
 dt.Rows.Add(dtrow)  
 dtrow = dt.NewRow()  
 ' Create New Row  
 dtrow("UserId") = 3  
 'Bind Data to Columns  
 dtrow("UserName") = "chandrababu"  
 dtrow("Education") = "B.Tech"  
 dtrow("Location") = "guntur"  
 dt.Rows.Add(dtrow)  
 dtrow = dt.NewRow()  
 ' Create New Row  
 dtrow("UserId") = 4  
 'Bind Data to Columns  
 dtrow("UserName") = "arun"  
 dtrow("Education") = "CA"  
 dtrow("Location") = "Guntur"  
 dt.Rows.Add(dtrow)  
 gvDetails.DataSource = dt  
 gvDetails.DataBind()  
 End Sub  
 End Class  

 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  


7:28 AM Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top