Joel,
Hold off on my previous answer, thinking about this there is no reason for
you to do this clientside.
Using the On_ItemDataboun d event will be important though.
What you need to do is create a counter to use within On_ItemDataboun d and
check for the row's id (If you don't want the id column to show then set it
to not be visible). Then, as your grid is bound, check the id to see if the
current item being bound is the row you want and select it.
So, for example, using a hidden ID you could write your code like this:
'---Dim a variable set to zero each time to track the current index within
the datbound event.
Private CurrentIndex As Int32 = 0
Private Sub DataGrid1_ItemD ataBound(ByVal sender As System.Object, ByVal e
As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
DataGrid1.ItemD ataBound
Try
Dim itemType As ListItemType = e.Item.ItemType
If ((itemType = ListItemType.Pa ger) Or (itemType =
ListItemType.He ader) Or (itemType = ListItemType.Fo oter)) Then
Return
Else
CurrentIndex += 1
If e.Item.Cells(0) .Text = "[Your ID Here]" Then
DataGrid1.Selec tedIndex = CurrentIndex
End If
End If
Catch ex As Exception
'---Handle Exception
End Try
End Sub
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate. com> wrote in
message news:e3******** ******@tk2msftn gp13.phx.gbl...
Joel,
Did you look at the example? There is some javascript in there inside of
the OnItemDatabound that selects the row clientside.
If you use that same script in a Page.RegisterSt artupScript you'd have
what you need.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Joel Reinford" <jr********@com cast.net> wrote in message
news:Ga******** ************@co mcast.com... Justin:
Thanks for the reply but I don't see that this has anything to do with my
question. I can select the row just fine from the UI just fine already. I
can also get the datakey value based on the selectedindex value. What I
want to do is reverse that process.
Joel Reinford
Data Management Solutions LLC
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate. com> wrote in
message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Joel,
I have some sample code on my website, www.aboutfortunate.com, that
shows how to make a row in a datagrid clickable. If you click the "Code
Library" link at the top of the page and then use the search box that
will appear to search for "make row clickable" the code will give you
some pointers.
If the sample code doesn't answer all your questions feel free to email
me.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Joel Reinford" <jr********@com cast.net> wrote in message
news:9J******** ************@co mcast.com...
I am looking for a way to set the selectedindex of a datagrid based on
the datakey value.
For example given this grid with a datakey of OrderID:
OrderID Item
54 A
98 B
102 C
263 A
If I have a value of 102, I'd like to have selectedindex = 2. The usage
for this is for selecting a specific row in the datagrid after
adding/deleting rows.
Joel Reinford
Data Management Solutions LLC