Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Gary Blakely #1
Create Columns Automatically at Runtime
We have been having some unexplainable datagrid issues and questions on this
subject and our messages have largely been ignored when posting to this
forum. I thought it might make sense to post a working example of our
problem in the simplest possible way.
In the program below, the web page has dataGrid1. the only thing that has
been done to it at design time is to check the "Create columns automatically
at runtime" checkbox - nothing else.
The code below does indeed create the visual grid as expected. Furthermore
the Cell contents and Item count all exist and contain expected values.
However there is no columns array !! After the databind, for instance,
DataGrid1.Columns(0) does not exist. There is therefore, no way to even
reference the HeaderText (which visually shows) or any other attribute of
the column.
Why is this?
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim SQLStr As String = "Select FirstName, LastName From
Employees"
Dim myConnection As New System.Data.SqlClient.SqlConnection
myConnection.ConnectionString = _
"workstation id=myMachine;user id=sa;data source=myMachine;" & _
"persist security info=True;initial
catalog=NorthWind;password=xxxxx"
myConnection.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand(SQLStr,
myConnection)
Dim da As New System.Data.SqlClient.SqlDataAdapter
da.SelectCommand = cmd
Dim dt As New DataTable
da.Fill(dt)
DataGrid1.DataSource = dt
DataGrid1.DataBind()
'at this point DataGrid1.Columns(0) does not exist
'however...
'DataGrid1.items(0).cells(0).text = "Nancy"
'DataGrid1.items.Count = 9
End If
End Sub
End Class
--
Regards,
Gary Blakely
Dean Blakely & Associates
[url]www.deanblakely.com[/url]
Gary Blakely Guest
-
How to add columns to AdvancedDataGrid at runtime?
Hi... Am working with Advanced Datagrid.. Any idea how to add columns into AdvancedDatagridColumnGroup at runtime.? means i need to call a... -
Creation and Positioning DataGrid Columns at runtime.
Hello, I need to create a DataGrid that looks something like this... <HyperLinkColumn><ButtonColumn><Data><Data><ButtonColumn> but I can only... -
Changing Datagrid columns at runtime
Dear all, I'm writing an ASP.NET application, which allows flexible editing of tables stored in an oracle database. Therefore, it is necessary to... -
Q: Default columns appear at runtime
Hi all, I dropped the DataGrid control onto my ASPX page, and it automatically appeared with the 3 default columns having headings of {Column0,... -
Adding Columns at runtime in datagrid control
have a datgrid control that has 3 columns defined at design time. Remaining columns are coming from a query and not known until runtime. I have...



Reply With Quote

