Display DataGrid's RowNumber in Bound column?

D

D. Shane Fowlkes

I have a DataGrid which is populated by a DataBind command and is bound to a
DataSet. It displays nicely on the page and all is well. Is it even
possible to have one of the "columns" filled with the row number of the
actual content from a field??

In other words...something to the effect of:
<asp:BoundColumn HeaderText="Record Number" DataField="<%#
MyDataSet("Budgets").Rows.Index %>"/>
<asp:BoundColumn...real fields....... />

It would be nice if I could display incrementing row numbers in my datagrid.

Thanks!
 
G

Guest

In C#.

Add a template column to your datagrid
<ASP:TemplateColumn><ItemTemplate><ASP:Label ID="lblRowCount" Runat="server"></ASP:Label></ItemTemplate></ASP:TemplateColumn

Then wire the ItemDataBound event of your datagrid
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e

Label lbl = (Label) e.Item.FindControl("lblRowCount")
if(lbl == null) return
lbl.Text = Convert.ToString(e.Item.ItemIndex + 1)


Suresh

----- D. Shane Fowlkes wrote: ----

I have a DataGrid which is populated by a DataBind command and is bound to
DataSet. It displays nicely on the page and all is well. Is it eve
possible to have one of the "columns" filled with the row number of th
actual content from a field?

In other words...something to the effect of
<asp:BoundColumn HeaderText="Record Number" DataField="<%
MyDataSet("Budgets").Rows.Index %>"/><asp:BoundColumn...real fields....... /

It would be nice if I could display incrementing row numbers in my datagrid

Thanks
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top