[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ordinal row positions in DataGrid/DataSet

Posted on 2005-05-17
7
Medium Priority
?
466 Views
Last Modified: 2010-04-07

I don't see properties for either the datagrid or dataset that indicates how to get .Count or ordinal position.

I'm binding a DataSet to a DataGrid and need to start working with the ordinal row positions in a couple differnt contexts. For example, i have a column holding numeric values and want to find which row number a given value is found in. And then I'd want to know total number of rows. Then I'd be able to produce, for example, "Row 3 of 40" output.

Also, and this is probably more complex...I have a templete column that holds links to script that 'moves up' and 'moves down'. The script will update the chosen record so the id field is incremented or decrimented.

<ItemTemplate>
    '<a href="#" onclick="javascript:popup('RowEdit.aspx?theAction=moveup&myID=<%# DataBinder.Eval(Container, "DataItem.myIdentity") %>', 'EditRow','scrollbars=yes,resizable=yes,width=600,height=300')">Move Up</a><br>
    '<a href="#" onclick="javascript:popup('RowEdit.aspx?theAction=movedown&myID=<%# DataBinder.Eval(Container, "DataItem.myIdentity") %>', 'EditRow','scrollbars=yes,resizable=yes,width=600,height=300')">Move Down</a><br>
</ItemTemplate>

I need a way to disable (or prefereably not display) the 'move up' link when outputting the first row of the datagrid - likewise disable the 'move down' link when rendering the bottom link.

Understanding that this may not be possible to proccess in the HTML portion of the page I'd need to see how to obtain those values and then append them to the querystring being constructed the same way I'm appending the 'myIdentity' field from the databinder.

0
Comment
Question by:juststeve
  • 3
5 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 1200 total points
ID: 14019373
Look into the ItemDataBound or ItemCreated Events the DataGrid Fires.  Each "row" in the datagrid has an index, that counts up, which you can easily get at in this sub.

e.Item.ItemIndex (the row # would be e.Item.ItemIndex + 1)

also, after the datagrid is bound, you can get a count of the rows using
myDataGrid.Items.Count

I see no reason why you can't get what you are after...so keep at it! :-)
0
 
LVL 23

Assisted Solution

by:b1xml2
b1xml2 earned 800 total points
ID: 14019517
The ItemIndex is good as long as you are aware of the following gotcha. The underlying data source in this case is the DataView and not DataTable. The individual "row" item is the DataRowView and not the DataRow. There's a difference here in that the DataView may show a subset of the DataTable.
 
0
 

Author Comment

by:juststeve
ID: 14034701
Couldn't seen the reference to index cuz I was looking for it in the toplevel of the members list helpfile. Next time I'll know to browse thro some likely links.

thankx to both...shouldda added and slit points...next time b1 (& i think we can all count on there being a 'next time').
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 14035673
whoa! so Page Editors can also reopen questions hmmmm!!!
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 14035862
too much responsibility... =))
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

872 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