[RESOLVED] [02/03] Datagrid column Count return 0 always ...
Hi all,
I have bind datagrid dynamically through coding .. it display 2 columns at runtime.
Now i want to make the First column align Right while second to Left.
So i tried to solve it using
VB Code:
DataGrid.Columns(0).Style.HorizontalAlignment = .....Right
But the problem i face is that when i use
VB Code:
Datagrid1.Datasource = ds.Tables(0)
'Response.Write(Datagrid.Columns.Count)
Datagrid1.Databinding()
Response.Write(Datagrid.Columns.Count)
it always gives 0
I know this problem is due to dynamic column binding. But don't know how to solve it..
Help me URGENT..
Re: [02/03] Datagrid column Count return 0 always ...
Could you just get the count off of your ds?
Re: [02/03] Datagrid column Count return 0 always ...
ok to be more specific..
VB Code:
DataGrid1.DataSource = ds.Tables(1)
Response.Write(ds.Tables(1).Columns.Count) ' This Return 2
Response.Write(DataGrid1.Columns.Count)' This Return 0
DataGrid1.DataBind()
Response.Write(ds.Tables(1).Columns.Count) ' This Return 2
Response.Write(DataGrid1.Columns.Count) '' This Return 0
I am using Dynamic binding..
Re: [02/03] Datagrid column Count return 0 always ...
But as I was saying its easier to just reference your datasets column collection. The columns collection is never used when dynamically generated. ;)
Quote:
Automatically generated columns are not added to the Columns collection.
Re: [02/03] Datagrid column Count return 0 always ...
** Bump **
Ok i want this ..
1. I want to bind datagrid dynamically
2. After then I want to right align first column of datagrid
Can u tell me how's that possible ?
Re: [02/03] Datagrid column Count return 0 always ...
I understood what Rob want to explain and I did my best to solve this. But Could't do anything to solve this.
I am currently using alternative method from backend.. But still desparate to know the solution.
Come on guys i have to solve this during this 2 hours. plz help me..
Re: [02/03] Datagrid column Count return 0 always ...
:D Sorry couldn't think of this easy method earlier..
VB Code:
DataGrid1.AutoGenerateColumns = False
DataGrid1.DataSource = ds.Tables(1)
Dim bCol As New BoundColumn
bCol.DataField = "FieldValue"
bCol.ItemStyle.HorizontalAlign = HorizontalAlign.Right
DataGrid1.Columns.Add(bCol)
DataGrid1.DataBind()
Hurrayieeeeee........ :p