Hi,
How can i make a bound field as the select button for selecting the row? For example when i click on the company name which is a field in gridview the respective row should get selected.. How to do that and even the selected row color should change.. How to do that as i do not want to autogenerate the select linkbutton .
Loading

NarayanPosted Oct 13, 2011, 11:54 PM
B M SuchitraPosted Nov 28, 2011, 12:36 AM
I have one more doubt. In the solution attachment what you have provided..
If i want to fetch the Emp Name when i select a row how do i get that?
Prabhu RajaPosted Oct 14, 2011, 3:16 AM
B M SuchitraPosted Oct 14, 2011, 2:44 AM
I am sorry. Your answer is correct. Actually i got confused because of linkbutton text which you have given as select.. That made me think that it is autogenerated select button.. thanks for the answer
Prabhu RajaPosted Oct 14, 2011, 1:58 AM
He used LinkButton inside of Template Field. the Text of link button is only "Select" but it actually a link button. and he used linkbutton event handler.
Go through the Code in .aspx. and .cs files
NarayanPosted Oct 14, 2011, 1:52 AM
Please go through the aspx and .cs file.
B M SuchitraPosted Oct 14, 2011, 12:21 AM
I do have the knowledge about that select but i do not want to do it like that. I have a templated field which is having a linkbutton.. At the click event of that linkbutton i want to change the color of the row. I also want to allow user to make only 1 selection at a time. How to do that?
My requirement is that i do not want the select button
B M SuchitraPosted Oct 13, 2011, 11:38 PM
It is still not working as it has to work[I mean color is not changing at linkbutton click].. I hope you are understanding my problem. I want row backcolor to change at linkbutton click and allow only 1 row selection at a time.. How can i do that please help..
Prabhu RajaPosted Oct 13, 2011, 7:41 AM
B M SuchitraPosted Oct 13, 2011, 6:23 AM
I get the below error:
An object reference is required for the non-static field, method, or property 'System.Web.UI.Control.NamingContainer.get'
Source Error:
Line 52: { Line 53: LinkButton btn = (LinkButton)sender; Line 54: GridViewRow gvr = (GridViewRow)LinkButton.NamingContainer; Line 55: int rowindex = gvr.RowIndex; Line 56: GVSearch.Rows[rowindex].Attributes.Add("onclick", "javascript:ChangeRowColor('" & GVSearch.Rows[rowindex].ClientID & "')");Prabhu RajaPosted Oct 13, 2011, 5:45 AM
B M SuchitraPosted Oct 13, 2011, 3:16 AM
Thats ok but that is not my requirement.. Actually that javascript which is below :
is correct but it allows for multiple row selection.. I want single row selected at a time
TulasiPosted Oct 13, 2011, 3:15 AM
TulasiPosted Oct 13, 2011, 3:07 AM
i done one sample example for u , chk this
Gridview source code
Link button click event
Please do not forget to mark "Accpeted Answer".
B M SuchitraPosted Oct 13, 2011, 3:02 AM
This link:
http://www.daniweb.com/web-development/aspnet/threads/202708 Allows for multiple row selection... I want user to make only 1 row selection at a time
B M SuchitraPosted Oct 13, 2011, 2:33 AM
Can we change the row backcolor at the gridview linkbutton click event? How to do that? Please help
TulasiPosted Oct 12, 2011, 6:26 AM
TulasiPosted Oct 12, 2011, 6:15 AM
have a look at these links
http://www.geekzilla.co.uk/view9FC28EE6-ACB0-4F51-BFE4-38B0B10134D5.htm
http://www.daniweb.com/web-development/aspnet/threads/202708
Please do not forget to mark "Accpeted Answer".
B M SuchitraPosted Oct 12, 2011, 5:51 AM
Either ways is ok for me
TulasiPosted Oct 12, 2011, 5:41 AM
Could u tel me whether u wan to change color by using javascript or codebehind ?
B M SuchitraPosted Oct 12, 2011, 5:32 AM
Your code does not work for me. I have a link button in gridview on clicking it row color should change.
TulasiPosted Oct 12, 2011, 4:46 AM
chk this i used checkbox to change color
//Javascript
function ChangeRowColor(obj) {
var rowobj = getParentRow(obj);
if (obj.checked)
{
rowobj.style.backgroundColor = '#cccccc';
}
else
{
rowobj.style.backgroundColor = 'white';
}
}
Gridview :
Please do not forget to mark "Accpeted Answer".