getting the row number in a datagrid

2

2obvious

I'm using a CustomValidator within a datagrid control. I'd like to
get the index of the item (i.e. row of the datagrid) when the
validator is fired and use this number in my custom function. Can
this be done?
 
M

matt.torline

Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted
to make sure you saw the levels. Also a while back I was trying to
deal with CustomValidators in datagrids, I seem to recall some issues
with that just FYI. Hope this helps AuSable Troutbum

'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender

'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent

'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent

'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)
 
2

2obvious

Oh, if only I knew all these relationships ahead of time...

I've been digging around in the .NET Framework site for a simple
diagram of what objects contain what objects, so I can get a better
feel for the object model. No success. Is there anything out there
like this?

Another, similar question: is there a simple way to get a control type
and put it in a string, so I can stick it in a label control on
postback or something? I've been trying to use the GetType() method,
with no success.
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top