Selecting a Datagrid row by clicking the row


I am trying to configure my Datagrid so that I can click anywhere on the row and it will invoke the OnItemCommand event and run the associated subroutine.
To do this I have created a datagrid with the following:

<asp:DataGrid id="dgrdTSOverview_Approved"
<asp:BoundColumn DataField="Period" HeaderText="Period"></asp:BoundColumn>
<asp:BoundColumn DataField="First_Name" HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Sur_Name" HeaderText="Sur Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Unit_name" HeaderText="Orgaisation"></asp:BoundColumn>
<asp:BoundColumn DataField="Week" HeaderText="Week"></asp:BoundColumn>
<asp:ButtonColumn ButtonType= "PushButton" Visible="false" CommandName="Edit" Text="Edit" />
I have also setup the Mouseover_Hover outine as follows:

Sub Mouseover_Hover(sender As Object, e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover", "'#DEE0E2','hand'")
e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" & "dgrdTSOverview_Approved:" & "_ctl" & (e.Item.ItemIndex + 2) & ":_ctl0','')")
End If
If e.Item.ItemType = ListItemType.Item Then
e.Item.Attributes.Add("onmouseout", "'White'")
e.Item.Attributes.Add("onmouseout", "'#EBECED'")
End If
End Sub

The problem is that when I click on the row I get an runtime error object expected. I think the problem is with the id of the button used in the onclick:
e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" & "dgrdTSOverview_Approved:" & "_ctl" & (e.Item.ItemIndex + 2) & ":_ctl0','')")
I am not sure if this is the correct ID for the button.
can anyone help please ?

11/24/2004 3:04:35 PM 24353 articles. 2 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 5

I think you need to replace the underscores with dollar signs
11/25/2004 1:56:31 PM
theres something on here that might help
11/25/2004 5:27:00 PM

Similar Artilces:

DataGrid Rollover Colors, select single, select multiple rows client side
Iam just adding some more lines to JakeJeck's post Put this in a class file         public static DataGridItem ApplyRowRollover(DataGridItem item , string MouseOverColor , string MouseOutColor, string MouseClickColor )         {             item.Attributes.Add("onmouseover", "ChangeColorOver(this,'" + MouseOverColor + "','" + MouseClickColor + "');");           ...

DataGrid Row selection at client side
I have a Datagrid and i need a functionality to set the row of a datagrid to a color(blue) when i click on the DataGrid row. I have a check box in the DataGrid Header if i select the checkbox all the rows in the datagrid are set with the color(blue) at client side. i wrote the code but it is giving problems. can you pls help me out in solving this problem. code is below: var selectedRow = null; function fnSelectRow(rowObject) {         if (selectedRow != null)         {                 selected...

Select row on row click?
Hello, the problem is the following one.I have a gridview with a lot of options (6 options in total) that means 6 icons at the end of each row, its veryugly, I want to create a toolbar(its already created)  , I want that the row be selectable with a single click on any part of the row, and when the row is clicked then I will show the toolbar and the user would be able to select any of the 6 options. Can somebdy please tell me how can I make the row clickable and selectable, and how can I make from the toolbar buttons to know wich row is selected T...

How to set the row number and get the row number for ("selected row) in Datagrid
I face a problem that i can't get the selected row of the datagrid in both server side script ( and client side script (javascript) As i can't use the button column / hyperlink column in the datagrid. Thus , i need to handle the change the background color of the selected row and also to get the selected row number for Update/Delete. Thanks in advance. This depends on how do you perform the selection. Do you want to implement chaning of the SelectedRow at the client side without any postback? If you have no issues with postback, then you can do s little trick here: 1. ...

I want to select top 3 rows except the first from 4 rows of a Table. It should select from top 2 row,top3 row and top4 row.
 Hi, Let say I've 4 rows in a table. I want to select top 3 rows except the first from 4 rows of a Table. It should select from top 2 row,top3 row and top4 row. Thanks in advance Asghar Ali Mohammed Designer and Developer)Do not forget to "MARK AS ANSWER" on the post that helped you. If you can use Linq, you can use Skip., EdMicrosoft MVP - ASP/ASP.NET Hii dear..U can fire the Query select Top(3) from Table1 order by id desc.. "A conclusion is whe...

select the row of the datagrid whose value is same as one of the value of row of datagrid
hellow all,  I have a datagrid which is bound to the ordertable,so all the orderdetails are shown on the page load. but my requirement is that,i have a textbox and a search button,when the user enter the order number in the text box and click on the search button the datagrid should show that record whose order number is entered by the user n most imp that the record may be in the 65th or 34th row of the datagrid,i wants to put it in the first row. how to do it. If there's a reason you can't filter down to just the one row, you'll have to come up with some paging algorithm that wil...

How to delete Datagrid row if that row is not selected
Hi, I faced a problem. I have a simple datagrid. It allows user to select a particular row of data say row 5. It works completely fine but if user wants to delete row 7 when row 5 is selected, the datagrid will delete 5 (which is the selected row) instead of 7. How to go about this issue? Thanks! Regards, FrancisSGDOTNET.ORG Can't you just select row 7 and delete it?Thanks!Bernie At first, DataGrid deletes nothing. It sends out only commands that your code has to handle. You have to use DeleteCommand event of datagrid. In this event you have to take the row index from event...

Datagrid Row Row/cell selection
I have a data grid that is displaying the results of a query to a database. It has 4 columns (say appID, FAQID, FAQ, Source). I have created the FAQ column as a TemplateColumn and set it as a LinkButton as I want a new page of the application to load when a user clicks on the FAQ. The new page is to display to complete solution to the FAQ. Is there any way that I can retrieve the value from the FAQID column that relates to the clicked FAQ so that I can pass this to the new usercontrol? Regards, Wallace You could certainly do this. Since you have the FAQID in the one of the ce...

Select a Row in DataGrid and Delete this Row
My goal is to put the Rows from one (left) GridView into the secend (right) GridVIew.For this I would like to use Drag and Drop becauce this would do just that but I can find only D&D features in e.g. Dojo. Is it possible in ASP.NET, too?Because I didn't find the D&D solution for ASP.NET I created two GridViews with a SELECT Label for choosing a Row. Then I chosen the SelectedIndexChanged event but when I want to delete the selected row then an error occurs that this isn't possible. Does anyone knows how I can solve my problem? Thank you!  Hello!!Plz see following lin...

How to display a client-side confirm dialog box if the user clicks on the first row in my datagrid
I could n implement that, this what I tried: I define my datagrid with :  <ItemTemplate> <a id="MenuItem".......><%#container............>  pls check my aspx html code bellow. Thn, In the ItemDataBound event handler of my datagrid, I test if e.Item.ItemIndex=0, if so, I create an object of type control and assign it to e.item.controls(0) , then I try to add the client side property: atributes(....) to that control. The pb is: the control object that I create doesn t take the client property :  attributes(“onclick”)=…. My question is:  What type are...

(CLIENT SIDE DATAGRID SEARCHING) Javascript code needed to scroll a scrollable datagrid to a specific row in datagrid?
I have a page that has a datagrid within a 'div' element, so that the datagrid is scrollable. Also, on the same page, I have a 'Search' button that searches the 'Invoice Number' column for an invoice number equal to the  value entered by the user in a textbox with id 'txtSearch'. Though I am able to find the invoice number and highlight its row using javascript, how can I make the scroll bar of div move vertically down to the position of the highlighted row of the datagrid using client side code?sun21170 Hello sun, i've never tried this, and don't know if there'...

selecting row in gridview by clicking anywhere in row (not just on 'select' link)
Hi there- I would like my gridview to behave such that a click anywhere in the (whole length of the) row would act just like clicking the "select" column link. Anyone have any code or suggestions?   You could use: ( but you would also need to disable event validation ) <%@ Page Language="VB" EnableEventValidation="false"%> Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Attributes.Add("onclick", "javascript:__doPostBack('GridView1','select$" &...

Iwant to select a row and column in gridview with select radiobutton. but No checked change event.below put a button .if click that button to seleced row values will select
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

Row cell click select entire row?
I am trying to mimic the UI from MS CRM in the grids sections of the application. If anyone knows how to use/get hold of that grid then please let me know otherwise here is the question.   I am able to bind data to a datalist. (using ASP.NET 1.1). That's all good HOWEVER, since each column is a table cell, within that contains the label to show the data for that row/column, how can I select the entire row when the user clicks on it (from client click perhaps)? So on any column of a row, when the user clicks, I want the entire row to be selected/highlighted.   how can I...

Web resources about - Selecting a Datagrid row by clicking the row -

Consultation Document on the Methods for Selecting the Chief Executive and for Forming the LegCo in 2012 ...
The " Consultation Document on the Methods for Selecting the Chief Executive and for Forming the LegCo in 2012 " was a document published on ...

Voting Machine Caught on Camera Casting Ballot for Democrat when Selecting Republican - YouTube
**UPDATE.... I've heard many reports that this is "just a calibration issue." I will say this... when I went to page 2 and began voting for city ...

Selecting decor that will move with the times
What colours should I use in my home so that my d&#233;cor is neutral and flexible but not boring?

Clock ticking on selecting successor to Leigh Clifford at Qantas
With Qantas on course to chalk up its largest annual profit since 2008, the question now is whether chairman Leigh Clifford is looking to hang ...

More to selecting political background music than indiscriminate meandering
Gathering a song to use as a protest weapon can backfire.

Jackie French: Why selecting the right place for your plants is important
The secret of growing anything easily is to choose the best spot for what you want to grow.

Liberals begin 'super weekend' of selecting delegates
A race for the top job in the federal Liberal party gained momentum on Friday as rank and file party members began the selection process for ...

Boston Marathon bombing trial: Judge, lawyers face challenges in selecting jurors - CTV News
As the second phase of jury selection began in the federal death penalty trial of Boston Marathon bombing suspect Dzhokhar Tsarnaev, it immediately ...

Selecting cabinet one of first orders of business for Trudeau
One of the first orders of business for any new prime minister is picking a cabinet. Who is likely to make the cut?

Agile Analysis, Self-Selecting Teams, TDD & BDD in Methods & Tools Winter 2014 issue
... for software developers, testers and project managers – has just published its Winter 2014 issue that discusses Agile Analysis, Self-Selecting ...

Resources last updated: 11/28/2015 10:45:54 PM