Displaying number of columns of a Datagrid...
I am developing a datgrid in vb.net
I gave response.write statement to get the number of columns in the datagrid.
VB Code:
sqlConn = New OracleConnection(State.sConnection)
sqlConn.Open()
sqlDa = New OracleDataAdapter(sqlsearchquery, sqlConn)
sqlDa.Fill(sqlDs)
DataGrid1.DataSource = sqlDs
DataGrid1.DataBind()
Response.Write("Datagrid Columns:" & DataGrid1.Columns.Count.ToString())
The Datagrid shows 17 columns on display.
But the response.write returns 0 columns. WHY ?
anybody please help on this.
Re: Displaying number of columns of a Datagrid...
Bind the Table to the Grid instead of the whole DataSet!
VB Code:
sqlConn = New OracleConnection(State.sConnection)
sqlConn.Open()
sqlDa = New OracleDataAdapter(sqlsearchquery, sqlConn)
sqlDa.Fill(sqlDs)
DataGrid1.DataSource = sqlDs[COLOR=DarkRed][B].Table(0)[/B][/COLOR]
DataGrid1.DataBind()
Response.Write("Datagrid Columns:" & DataGrid1.Columns.Count.ToString())
Re: Displaying number of columns of a Datagrid...
NO, IT IS ALSO GIVING ME 0..
This is the code I used for this (.Net 2003)
VB Code:
Dim sqlDa As OracleDataAdapter
Dim sqlConn As OracleConnection
Dim sqlDs = New DataSet
Dim sqlQuery As String
sqlConn = New OracleConnection(State.sConnection)
sqlConn.Open()
sqlDa = New OracleDataAdapter(sqlsearchquery, sqlConn)
sqlDa.Fill(sqlDs)
DataGrid1.DataSource = sqlDs.Tables(0)
DataGrid1.DataBind()
Response.Write("Datagrid Columns:" & DataGrid1.Columns.Count.ToString())
Re: Displaying number of columns of a Datagrid...
What type of Grid is this ???
Cause System.Windows.Forms.DataGrid did'nt have Columns property :sick:
Emm and what about this ?
VB Code:
Dim sqlDa As OracleDataAdapter
Dim sqlConn As OracleConnection
Dim sqlDs As New DataSet [I]' You forget the AS here (Instead of Dim sqlDs = New DataSet)[/I]
Dim sqlQuery As String
sqlConn = New OracleConnection(State.sConnection)
sqlConn.Open()
sqlDa = New OracleDataAdapter(sqlsearchquery, sqlConn)
sqlDa.Fill(sqlDs)
DataGrid1.DataSource = sqlDs.Tables(0)
DataGrid1.DataBind()
Response.Write("Datagrid Columns:" & [COLOR=DarkRed][B]sqlDs.Tables(0).Columns.Count[/B][/COLOR]
Re: Displaying number of columns of a Datagrid...
yes, this gives me the number of columns from the dataset.
But I want the number of columns from the Data Grid only.
Coz, I want to set the Column Heading of the Data Grid, which is retrieved from another Dataset. Iam using the below code,
...after data binding....
DataGrid1.Columns(0).HeaderText = sqlDs1.Tables(0).Rows(0).Item(0).ToString()
This gives me error like "Index out of Range".
Re: Displaying number of columns of a Datagrid...
Quote:
Originally Posted by VB_client
yes, this gives me the number of columns from the dataset.
But I want the number of columns from the Data Grid only.
Coz, I want to set the Column Heading of the Data Grid, which is retrieved from another Dataset. Iam using the below code,
...after data binding....
DataGrid1.Columns(0).HeaderText = sqlDs1.Tables(0).Rows(0).Item(0).ToString()
This gives me error like "Index out of Range".
Is this ASP.NET ??
It really strange cause DataGrid from FrameWork 1.1 did'nt have Columns Propetry, is this something that you add youself? or third party?
And DataGrid Style should be done with DataGridTableStyle and DataGridColumnStyle.
All of this is define here:
http://msdn.microsoft.com/library/de...lumnstyle1.asp
Re: Displaying number of columns of a Datagrid...
Yes, Its ASP.NEt and I am using framework 1.1 and the datagrid has Column properties.
Re: Displaying number of columns of a Datagrid...
Since this is ASP.NET why don't you post at the ASP.NET Forum ?
Not that i don't want to help, but Since this is the VB.NET Forum, are you expecting to receive ASP.NET answer here :rolleyes:
thing are a bit different in ASP.NET... :rolleyes:
Regard
Re: Displaying number of columns of a Datagrid...
I thought it was something like this.
Datagrid1.items.Cells.Count or something like that.
:bigyello:
Update:
Here is the proper way --
Datagrid1.Items(0).Cells.Count()
assuming that there are rows in the datagrid (which there should be if you populated it with data! :p )
Re: Displaying number of columns of a Datagrid...
Okay, Thanks, I'll do it rightaway!