473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Display DataGrid's RowNumber in Bound column?

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
1 4087
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Morné | last post by:
Hi how do I validate a text value in a datagrid e.g. the user is only allowed to type in a Y or a N. I specifically have a problem with using the PropertyDescriptorCollection. I get the...
11
by: Junkguy | last post by:
I need some help programmatically causing a row in a DataGrid to "flush" its contents to its bound data (in Visual Studio 6 using Windows Forms with C#). My issue is I want to send an update to...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
4
by: Roger | last post by:
I have a datagrid and would like to know what even fires when a cell is changed? I want to know when the user changes a cell and moves to the next. I have some code that needs to be done to...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
0
by: Matt | last post by:
I derived my own custom class from the datagrid class. I overrode the ProcessCmdKey Function, like this, to catch the up and down arrow keys: ====== Protected Overrides Function...
1
by: s26f84 | last post by:
Hey Guys Alot of articles and alot of stuff still no answer. Please help me on this one. I need to get data out of a filterred selected row !!! ... this is how my code looks like.... On...
6
by: Doug Bell | last post by:
Hi I have a DataGrid with some hidden columns and also some read Only and some ComboBox Columns. Sandard Tabbing through the Datagrid sees the focus go to the hidden columns requiring further...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.