Asp.net grid view column count
I am using asp.net with vb. Here i bind data to Gridview. This Dataset has 5 records with 3 columns and also gridview shows that 5 records with 3 columns. But Gridview.columns.count property return 0. i want to get that colunm count. please help me sir.
dim lcolumncount as integer
GridView1.DataSource = ExecuteDataSet("Select Master_TypeID,Master_TypeName,Master_TrimName from Mastertype")
GridView1.DataBind()
lcolumncount = Gridview.columns.count
here always开发者_开发技巧 lcolumncount rerurn 0. i want 3.
You have to set the row to count first
GridView1.Rows(0).Cells.Count
Is there a typo in your code - you're binding the DataSet to Gridview1 but getting the column count from Gridview (without the 1).
At exactly which point are you calling DataBind() and then trying to access the column count? Your code is messed up so i suspect that you are not getting the column count immediately after binding.
With your code you posted, you are using GridView1
, but when accessing the column count you are using GridView
(without the 1
), which makes me think your code copy & paste is a little inaccurate.
dim lcolumncount as integer
GridView1.DataSource = ExecuteDataSet("Select Master_TypeID,Master_TypeName,Master_TrimName from Mastertype")
GridView1.DataBind()
lcolumncount = Gridview.columns.count
lcolumncount = Gridview.columns.GetColumnCount(0) will return total counts of fields in the grid visible and invisible included.
lcolumncount = Gridview.DisplayedColumnCount(0) Returns only the number of fields that are shown.
Good luck
lcolumncount = Gridview.columns.count(0)
will return the total count of fields in the grid both visible and invisible.
But lcolumncount = Gridview.DisplayedColumnCount(0)
returns only the number of fields that are shown.
精彩评论