|
-
Nov 14th, 2005, 11:03 AM
#1
Thread Starter
Lively Member
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.
In order to be successful all you need is a little faith within yourself
-
Nov 14th, 2005, 11:06 AM
#2
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())
-
Nov 14th, 2005, 11:15 AM
#3
Thread Starter
Lively Member
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())
In order to be successful all you need is a little faith within yourself
-
Nov 14th, 2005, 11:25 AM
#4
Re: Displaying number of columns of a Datagrid...
What type of Grid is this ???
Cause System.Windows.Forms.DataGrid did'nt have Columns property
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]
-
Nov 14th, 2005, 11:51 AM
#5
Thread Starter
Lively Member
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".
In order to be successful all you need is a little faith within yourself
-
Nov 14th, 2005, 11:56 AM
#6
Re: Displaying number of columns of a Datagrid...
 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
-
Nov 14th, 2005, 01:37 PM
#7
Thread Starter
Lively Member
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.
In order to be successful all you need is a little faith within yourself
-
Nov 14th, 2005, 01:50 PM
#8
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 
thing are a bit different in ASP.NET...
Regard
-
Nov 14th, 2005, 02:11 PM
#9
Hyperactive Member
Re: Displaying number of columns of a Datagrid...
I thought it was something like this.
Datagrid1.items.Cells.Count or something like that.

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! )
Last edited by rplcmint; Nov 14th, 2005 at 06:08 PM.
-
Nov 14th, 2005, 02:25 PM
#10
Thread Starter
Lively Member
Re: Displaying number of columns of a Datagrid...
Okay, Thanks, I'll do it rightaway!
In order to be successful all you need is a little faith within yourself
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|