ASP.Net 2.0 : how to set the selectedrow

S

Steve B.

Hi,

I'm building an ASP.Net 2.0 web application that uses the gridview control
(read only).
This gridview is filled by a DataTable which is the result of the select
method of an object binding source (which is a WebService but I don't think
it matters).

I also have a querystring parameter "id" and I want to "Select" the row of
the gridview that match one of its column (which is the primary key of my
table).

I did not succeed in setting the .SelectedRow since it's a readonly
property. I also tryed to set the selectedindex of the gridview, but I don't
know the index of the row before the databind.

How can I reach my goal ?

Thanks in advance,
Steve
 
J

Jester98x

Steve,

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If GridView1.Rows(e.Row.RowIndex - 1).Cells(1).Text = "Search Text"
Then
e.Row.RowState = DataControlRowState.Selected
End If
End If
End Sub

The above code in the code behind page should do the job. Change the
index of the Cells collection and the value you are check for to decide
if the row is selected or not.

The GridView must be configured with Enable Selection otherwise you
will get an error.

Regards,
Steve
 
S

Steve B.

I was confused because the XML documentation of the property RowState is
"Get the ...." and not "Gets or sets the..." like the documentation
convention is supposed to be...

Thanks for this lighting !
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top