C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Dynamic DataGrid


Posted Date: 02 Jul 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: UltimateRenganMember Level: Diamond    
Rating: 1 out of 5Points: 2



Bind the textbox values to Datagrid in run time.We can create the DataGrid in Runtime.

Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page

Dim DynamicDataGrid As DataGrid
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Just Drag and drop the Two Textbox and One button controls to Page
End Sub
Sub bindDatgrid()
DynamicDataGrid = New DataGrid
DynamicDataGrid.Width = 400
DynamicDataGrid.Height = 100
DynamicDataGrid.GridLines = GridLines.Both
DynamicDataGrid.CellPadding = 1
DynamicDataGrid.ForeColor = System.Drawing.Color.Black
DynamicDataGrid.BackColor = System.Drawing.Color.Beige
DynamicDataGrid.AlternatingItemStyle.BackColor = System.Drawing.Color.Gainsboro
DynamicDataGrid.HeaderStyle.BackColor = System.Drawing.Color.Brown
form1.Controls.Add(DynamicDataGrid)

Dim dt As New DataTable
Dim col1 As New DataColumn
Dim col2 As New DataColumn
Dim row1 As DataRow
'column One
col1.DataType = Type.GetType("System.String")
col1.ColumnName = "Name"
dt.Columns.Add(col1)
row1 = dt.NewRow
row1(0) = TextBox1.Text
dt.Rows.Add(row1)
'column Two
col2.DataType = Type.GetType("System.String")
col2.ColumnName = "Location"
dt.Columns.Add(col2)
row1(1) = TextBox2.Text
DynamicDataGrid.DataSource = dt
DynamicDataGrid.DataBind()


End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
bindDatgrid()
End Sub
End Class




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Dynamic DataGrid  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Sending SMS Through .NET
Previous Resource: Add Handler and Remove Handler at Runtime
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use