Datagrid Columns

J

J. Shane Kunkle

I have a datagrid that contains a bunch of boundcolumns:

<asp:datagrid id="DataGrid1" runat="server" autogeneratecolumns="False">
<columns>
<asp:boundcolumn datafield="Column1" sortexpression=" Column1" />
<asp:boundcolumn datafield="Column2" sortexpression=" Column2" />
<asp:boundcolumn datafield="Column3" sortexpression=" Column3" />
...
</columns>
</datagrid>

On the ItemDataBound event for the DataGrid I need to return the index of
the column with a specific key (key is the name of the column in the
database that the column is databound to - ie "Column1", "Column2", etc).

I thought this would be very easy to do - just iterate through the
DataGrid1.Columns collection - however I can't find any properties of the
DataGridColumn that corresponds to the name of the column that it's bound
to.

Any ideas? Am I looking in the wrong place - wrong approach?

Any help or advice is very appreciated - thanks in advance,
J. Shane Kunkle
(e-mail address removed)
 
J

J. Shane Kunkle

Thank you for your response.



I thought about this kind of approach - I could key off of the column Header
(and I also could use the sortexpression I suppose) but I would like to
avoid making these restrictions when designing this control. There is no
guarantee that uses of this control will name the column header text or the
sort expression the same as the bound database column id.
 
E

Eliyahu Goldin

DataField property of BoundColumn class is what you are looking for.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top