Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Jon Edney #1
When you bind an array to a datagrid, what's the field name?
In ASP.NET v2.0, I can successfully bind a generic datagrid to a 1 dimensional
array. But, now I want to customise the column header. I think I need to
make the first column (the one having data in the array) a "BoundColumn" and
set the HeaderText property, but the problem is that the BoundColumn wants
a DataField name. There is none! So how do I bind this one column to the
array column when the array doesn't have column names?
Example
=======
Code
----
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim test() As String = New String() {"one", "two", "three", "four","five"}
Me.DataGrid1.DataSource = test
Me.DataGrid1.DataBind()
End Sub
Results
-------
Item
one
two
three
four
five
It looks like the column name "Item" should work... but it doesn't!
Thanks,
Jon.
Jon Edney Guest
-
#36961 [Com]: mssql_bind will not bind an image field
ID: 36961 Comment by: rnerovich at gmail dot com Reported By: nerovichr at hotpop dot com Status: Open Bug... -
Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked.
I am trying to update the database field when the checkbox is clicked. I am trying to modified the following solution but.. got stuck on the... -
CFGRID with bind to text field --- IS IT ME????!
Ok...I'll keep it simple. I cannot get the binding feature to work in CF with cfgrid and cfform together. I am taking the example from the... -
custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid
I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of... -
Bind Paramaters To An Array
Using flash remoting I have a stack of paramaters and then I have an array items I want to bind them to. Currently I just use the ... -
Brock Allen #2
Re: When you bind an array to a datagrid, what's the field name?
You'll have to either set a HeaderTemplate for each column or handle the
DataBound event for the header row and change it manually.
-Brock
DevelopMentor
[url]http://staff.develop.com/ballen[/url]
> In ASP.NET v2.0, I can successfully bind a generic datagrid to a 1
> dimensional
> array. But, now I want to customise the column header. I think I
> need to
> make the first column (the one having data in the array) a
> "BoundColumn" and
> set the HeaderText property, but the problem is that the BoundColumn
> wants
> a DataField name. There is none! So how do I bind this one column to
> the
> array column when the array doesn't have column names?
> Example
> =======
> Code
> ----
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Dim test() As String = New String() {"one", "two", "three",
> "four","five"}
> Me.DataGrid1.DataSource = test
> Me.DataGrid1.DataBind()
> End Sub
> Results
> -------
> Item
> one
> two
> three
> four
> five
> It looks like the column name "Item" should work... but it doesn't!
>
> Thanks,
> Jon.
Brock Allen Guest
-
Jon Edney #3
Re: When you bind an array to a datagrid, what's the field name?
Hi,
Thanks for your email.
I have tried setting the column header on the DataBound event of the Grid,
but it doesn't believe the automatically generated columns exist. I get an
out of bounds error message. I've checked the code using normally bound
fields, and it works fine.
Could you give me a bit more info on the column template suggestion? I'm not
entierly sure what you are suggesting.
Thanks,
Jon.
"Brock Allen" wrote:
> You'll have to either set a HeaderTemplate for each column or handle the
> DataBound event for the header row and change it manually.
>
> -Brock
> DevelopMentor
> [url]http://staff.develop.com/ballen[/url]
>>> > In ASP.NET v2.0, I can successfully bind a generic datagrid to a 1
> > dimensional
> > array. But, now I want to customise the column header. I think I
> > need to
> > make the first column (the one having data in the array) a
> > "BoundColumn" and
> > set the HeaderText property, but the problem is that the BoundColumn
> > wants
> > a DataField name. There is none! So how do I bind this one column to
> > the
> > array column when the array doesn't have column names?
> > Example
> > =======
> > Code
> > ----
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> > Dim test() As String = New String() {"one", "two", "three",
> > "four","five"}
> > Me.DataGrid1.DataSource = test
> > Me.DataGrid1.DataBind()
> > End Sub
> > Results
> > -------
> > Item
> > one
> > two
> > three
> > four
> > five
> > It looks like the column name "Item" should work... but it doesn't!
> >
> > Thanks,
> > Jon.
>
>Jon Edney Guest
-
Brock Allen #4
Re: When you bind an array to a datagrid, what's the field name?
Just make your template like this (instead of a BoundColumn):
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>Your Header Goes Here</HeaderTemplate>
<ItemTemplate><%# Container.DataItem %></ItemTemplate>
</asp:TemplateColumn>
</Columns>
-Brock
DevelopMentor
[url]http://staff.develop.com/ballen[/url]
> Hi,
>
> Thanks for your email.
>
> I have tried setting the column header on the DataBound event of the
> Grid, but it doesn't believe the automatically generated columns
> exist. I get an out of bounds error message. I've checked the code
> using normally bound fields, and it works fine.
>
> Could you give me a bit more info on the column template suggestion?
> I'm not entierly sure what you are suggesting.
>
> Thanks,
> Jon.
> "Brock Allen" wrote:
>>> You'll have to either set a HeaderTemplate for each column or handle
>> the DataBound event for the header row and change it manually.
>>
>> -Brock
>> DevelopMentor
>> [url]http://staff.develop.com/ballen[/url]>>> In ASP.NET v2.0, I can successfully bind a generic datagrid to a 1
>>> dimensional
>>> array. But, now I want to customise the column header. I think I
>>> need to
>>> make the first column (the one having data in the array) a
>>> "BoundColumn" and
>>> set the HeaderText property, but the problem is that the BoundColumn
>>> wants
>>> a DataField name. There is none! So how do I bind this one column to
>>> the
>>> array column when the array doesn't have column names?
>>> Example
>>> =======
>>> Code
>>> ----
>>> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>>> System.EventArgs) Handles MyBase.Load
>>> Dim test() As String = New String() {"one", "two", "three",
>>> "four","five"}
>>> Me.DataGrid1.DataSource = test
>>> Me.DataGrid1.DataBind()
>>> End Sub
>>> Results
>>> -------
>>> Item
>>> one
>>> two
>>> three
>>> four
>>> five
>>> It looks like the column name "Item" should work... but it doesn't!
>>> Thanks,
>>> Jon
Brock Allen Guest



Reply With Quote

