473,394 Members | 1,722 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,394 software developers and data experts.

How to select a gridview row

83
Hii experts,
I've been trying for this but i didn succeeded.The problem is
I've a datagird which is having 2 cols displaying name and emial id .wht i want is when i select a paricular row from the gridview i want to capture the emial id value of tht paricular row.
I've added this code in the even onrowdatatbound.
Expand|Select|Wrap|Line Numbers
  1. protected void GridViewParticipants_OnRowDataBound(object sender, GridViewRowEventArgs e) 
  2.  
  3. .
  4. if (e.Row.RowType == DataControlRowType.DataRow)
  5. {
  6. e.Row.ID = e.Row.Cells[0].Text.ToString();
  7. e.Row.Attributes.Add("onclick", "javascript:Ongridrowselected('"+e.Row+ "','" + e.Row.Cells[0].Text + "')");
  8. e.Row.Attributes.Add("onmousehover", "javascript:Ongridrowmousehover('" + e.Row + "')"); 
  9. }
  10. The below are th two javascript functions.
  11. var lastselectedrow; 
  12. var originalcolor;
  13.  
  14. function Ongridrowselected(row,emailid) 
  15. {
  16.  
  17. var hidden=document.getElementById('hdnemailid') 
  18. hidden.value=emailid;
  19.  
  20. if(lastselectedrow !=row) 
  21. {
  22.  
  23. if(lastselectedrow != null) 
  24. {
  25.  
  26. lastselectedrow.style.backgroundColor=originalcolo  r;
  27.  
  28. lastselectedrow.stylr.color='Black';lastselectedro  w.style.fontWeight='normal'; 
  29. }
  30.  
  31. originalcolor=row.style.backgroundColor;
  32.  
  33. row.style.backgroundColor='BLACK'; 
  34. row.style.color='White';
  35.  
  36. row.style.fontWeight='normal'; 
  37. lastselectedrow=row;
  38.  
  39. }
  40.  
  41. }
  42.  
  43. function Ongridrowmousehover(row) 
  44. {
  45.  
  46. row.style.cursor='hand'; 
  47.  
  48.  }
Dont know why the rows are not getting selected when i place the mouse on the row.
Plz tell me ehr is thr mistake.
Thank you..
**sorry for the bad english.
Regards,
BTR.
[/SIZE]
Jan 16 '09 #1
4 5975
btreddy
83
Hii experts,

I've been trying for this but i didn succeeded.The problem is

I've a datagird which is having 2 cols displaying name and emial id .wht i want is when i select a periculer row from the gridview i want to capture the emial id value of tht perticuler col.

I've added this code in the even onrowdatatbound.
Expand|Select|Wrap|Line Numbers
  1. protected void GridViewParticipants_OnRowDataBound(object sender, GridViewRowEventArgs e)
  2.  
  3.  
  4. .
  5.  
  6. .
  7.  
  8.  
  9.  
  10. if (e.Row.RowType == DataControlRowType.DataRow) 
  11. {
  12.  
  13. e.Row.ID = e.Row.Cells[0].Text.ToString();
  14.  
  15. e.Row.Attributes.Add("onclick", "javascript:Ongridrowselected('" +e.Row+ "','" + e.Row.Cells[0].Text + "')");e.Row.Attributes.Add("onmousehover", "javascript:Ongridrowmousehover('" + e.Row + "')"); 
  16. }
  17.  
  18. The below are th two javascript functions.
  19.  
  20. var lastselectedrow; 
  21. var originalcolor;
  22.  
  23. function Ongridrowselected(row,emailid) 
  24. {
  25.  
  26. var hidden=document.getElementById('hdnemailid') 
  27. hidden.value=emailid;
  28.  
  29. if(lastselectedrow !=row) 
  30. {
  31.  
  32. if(lastselectedrow != null) 
  33. {
  34.  
  35. lastselectedrow.style.backgroundColor=originalcolor;
  36.  
  37. lastselectedrow.stylr.color='Black';lastselectedrow.style.fontWeight='normal'; 
  38. }
  39.  
  40. originalcolor=row.style.backgroundColor;
  41.  
  42. row.style.backgroundColor='BLACK'; 
  43. row.style.color='White';
  44.  
  45. row.style.fontWeight='normal'; 
  46. lastselectedrow=row;
  47.  
  48. }
  49.  
  50. }
  51.  
  52. function Ongridrowmousehover(row) 
  53. {
  54.  
  55. row.style.cursor='hand'; 
  56.  
  57.  
  58. }
Dont know why the rows are not getting selected when i place the mouse on the row.

Plz tell me ehr is thr mistake.

Thank you..

**sorry for the bad english.

Regards,

BTR.
Jan 16 '09 #2
acoder
16,027 Expert Mod 8TB
Post the client-side version of your code (in code tags please).

A few notes:
1. check typos: I see a stylr instead of style.
2. check errors in your error console: it should highlight any errors
3. It's onmouseover, not onmousehover
4.'hand' is not a valid cursor value. It should be 'pointer'.
Jan 16 '09 #3
btreddy
83
Hiii acoder ,Thanks for your reply.

I correctd the typo errors....but its not working .

i put a breakpoint ,its showing tht the value os e.Row.Cells[0].Text as "null".


client-side version code means the source code you are asking ,right.(IE-->View-->Source) .

Its a very huge file...can not post it here.
Jan 16 '09 #4
acoder
16,027 Expert Mod 8TB
You only need to post the relevant parts - not the whole page. Alternatively, post a link to a page that we can look at.
Jan 16 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David Hubbard | last post by:
I am using a GridView to display a set of objects that have a parent-child relationship. Each object, MyBO, has an ID property that is used to get the children of that object. class MyBO { ...
4
by: Dabbler | last post by:
Is there a way to let the user select a gridview row by clicking anywhere in the row (e.g. on any column)? The gridview would be readonly and I would like to bring up a detailview of the row the...
6
by: Terry | last post by:
Good morning! How do I determine which SELECT button was clicked in a GridView? The multiple SELECT buttons will be used for an application approval process. Thank you in advance for your...
1
by: K B | last post by:
Hi. I have a gridview with sqldatasource, etc. For the grid, I also have a search textbox. If the user needs to filter the records, I want to dynamically adjust the SELECT statement for the...
0
by: jmacduff | last post by:
Big question: How to enable edit/update commands to work when setting the sqldatasource select command from code behind. Details: I have a GridView using a sqldatasouce with the select and...
0
by: jobs | last post by:
I have a gridview that times when selecting from specific table when I try to when I add a where clause. Even when I'm only seleting Top 1 which comes right back at the command line. I test the...
4
by: Luqman | last post by:
I have populated the Child Accounts and Parent Accounts in a Grid View Control, I want to hide the Select Column of Parent Accounts, but not the Child Accounts, is it possible ? I am using VS...
5
by: Dinu | last post by:
hi how can we select a row in a gridview with out select column and get events fired thanks
2
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire column. When I set the...
15
JustRun
by: JustRun | last post by:
I have a problem with the select option at the gridview and gonna pull my hair out cause it doesn't work at all. Here is the Grid view code: I want to get the selected row when the user click...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.