473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

ASP.Net 2.0 : how to set the selectedrow

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
Dec 8 '06 #1
2 7728
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

Dec 8 '06 #2
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 !
"Jester98x" <st**********@wdr.co.uka écrit dans le message de news:
11**********************@f1g2000cwa.googlegroups.c om...
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

Dec 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike L | last post by:
I want my datagrid to only select rows, not cells. Here is my code so far. I think I'm really close. This code still selects just cell, but I want the row selected, and if the user arrows up or...
4
by: Amy | last post by:
I need some help. I have this table with alternate row colors. Class gray and class white. I have javascript that do highlight when mouseover row ... and onclick to select row and highlight it...
3
by: mosscliffe | last post by:
I have a gridview and in the GridView1_SelectedIndexChanged routine I am attempting to get at the data in the row I have done it successfully with cells 'Access the contents of a field in a...
3
by: HaVoK | last post by:
Hello, my problem: i want to get the values of the selected rows of a GridView. I have a button in every row and want to get the actual values e.g. of cell 1 of the actual row. How can i get...
7
by: Badis | last post by:
Hi, I've a radiobutton in my gridview and I want to dislpay the value in a cell of the selected value on the RadioButton click using this code : TextBox.Text =...
0
by: Badis | last post by:
Hi Guys, I have a TemplateItem that has a RaioButton on it, and I want to get the index of the selected row once clicking the RadioButton (RadioButton_Click event) any Ideas. Thanks
2
by: Andy Baker | last post by:
I have a VB.NET 2003 application that uses several datagrids. The behaviour I want from the datagrid is to select (highlight) the entire row when I click on any cell in a row. I have done this...
3
by: ygjyothi | last post by:
Hi All, I'm trying to integrate Ext2.0 and Dojo 1.0 i.e the selected rows from a Ext 2.0 Grid upon a button click should generate a Dojo 1.0 Chart in a pop up window or Ext.window.There is a Ext...
5
by: brendanmcdonagh | last post by:
Hi, I am accessing my jtable via sf1.setText((String)table.getValueAt(selectedRow, 1)); sf2.setText((String)table.getValueAt(selectedRow, 2)); ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.