Datagrid + display Row number

Posted on 2004-08-16
Medium Priority
Last Modified: 2011-09-20
i have a datagrid that show standings i want to add a colum that wil display the number of the row ie 1 thru 10, plus also when the use goes to the standings i want their name bold so it stands out, i will get their name form the authentication cookie and it will match the name colum


Position     Name       Pts
1              abcd         10
2              efghk         9
3              keyname    8   <-- currently logged in so this would be highlighted.

Question by:dkilby
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Author Comment

ID: 11817620
sorry forgot to add, i am using VB.net
LVL 21

Accepted Solution

tovvenki earned 1000 total points
ID: 11817775
for row numbers add a template column as the first column of the grid. As each row is rendered, the code behind the OnItemCreate event will update the text of this column based on the row index from the dataset. Each row of the dataset has an index property that can be used to compute the row number:

Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            e.Item.Cells(0).Text = (e.Item.DataSetIndex + 1).ToString()
        End If

    End Sub


Author Comment

ID: 11820654
LVL 10

Assisted Solution

jnhorst earned 1000 total points
ID: 11826182
adding to tovvenki's post:

then check the name against your auth cookie and add <b> & </b> tags to the text of the name cell.  In your sample above, Name is the second column so I will assume the index of the column is 1.

If {authCookie value} = e.Item.Cells(1).Text Then
     e.Item.Cells(1).Text = "<b>" & e.Item.Cells(1).Text & "</b>"
End If

LVL 21

Expert Comment

ID: 11827483
I am sorry I missed that one. jnhorst is correct add that too.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question