By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,166 Members | 1,695 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,166 IT Pros & Developers. It's quick & easy.

Display DataGrid's RowNumber in Bound column?

P: n/a
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!
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.