 |
|
|
 |
|
 |
I was looking for a solution. Thanks .. it worked.
|
|
|
|
 |
|
 |
Nice example. Works great until I do a postback that adds more elements to the page. When the page is posted back the Ids on the tr elements are not present so the javascript fails. Any ideas on how to correct this?
before postback
<tr id="ctl00_ContentPlaceHolder1_ActivitiesGridView1_ctl02" valign="top" onclick="javascript:ChangeRowColor('ctl00_ContentPlaceHolder1_ActivitiesGridView1_ctl02')" style="color:#333333;background-color:#FFFBD6;">
after a postback
<tr valign="top" onclick="javascript:ChangeRowColor('ctl00_ContentPlaceHolder1_ActivitiesGridView1_ctl02')" style="color:#333333;background-color:#FFFBD6;">
|
|
|
|
 |
|
 |
thanx nice code this is what i need
|
|
|
|
 |
|
|
 |
|
 |
Hey faraz it helped me alot. Thanks
But in previousColor case you can make this more generalize, right now you are changing PreviousRowColor into white, which wont be same in all cases. You may update your code something like this.
<script type="text/javascript">
//variable that will store the id of the last clicked row
var previousRow;
var previousColor;
function ChangeRowColor(row)
{
//If last clicked row and the current clicked row are same
if (previousRow == row)
return;//do nothing
//If there is row clicked earlier
else if (previousRow != null)
//change the color of the previous row back to white
document.getElementById(previousRow).style.backgroundColor = previousColor;
//change the color of the current row to light yellow
previousColor=document.getElementById(row).style.backgroundColor;
document.getElementById(row).style.backgroundColor = "orange";
//assign the current row id to the previous row id
//for next row to be clicked
previousRow = row;
}
</script>
Thanks
NOuman Rasheed
may i get your id over there?
|
|
|
|
 |
|
 |
Very Nice.....I too works in the UAE in the same field
|
|
|
|
 |
|
 |
Hi,
Your solution works perfectly except I am having issues with postback. Initially, I click a row in grid - it changes row color fine. However, if I select a different item from a drop-down list on my page, everything is refreshed (including grid) and then it wont highlight row anymore.
I tried a different solution than yours first, and found through alerts in my javascript that it found the grid (was not null) but its rows.length had changed to 0 even though there were rows in the grid. Please explain how this should be handled. Thank you so much!
|
|
|
|
 |
|
 |
Well what is in the code is completely client side and will not handle things for postback. How ever if you can keep track of what rows are clicked and color is changed you might be able to change the color again on postback for which you have to write additional code.
Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
|
|
|
|
 |
|
 |
Hmmm, I added a bunch of alerts to the javascript and it works MOST of the time. Every so often if I select another item in dropdown and grid rebinds, it will highlight on the first click and then nothing. Very strange. Your functions passing of clientID is definitely better than the other way... I'll just keep monitoring it for now. Thanks again.
|
|
|
|
 |
|
 |
It is a good work I appreciate it .Keep it up
|
|
|
|
 |
|
 |
This isn't an article, it's a piece of fluff
Jon
Smith & Wesson: The original point and click interface
|
|
|
|
 |
|
 |
Thanks for the comments indeed its quite simple, probably for you and me but what about those people who ask how to display MessageBox through javascript. It is mainly for beginners.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
 |
|
|
 |
|
 |
I checked that artcile written by Azam, well bro first why do I need to copy the code, second searching on internet can bring almost everything in front of you, so if I have copied any thing I must have changed it. Most importantly such childish act neither suits my qualification nor my experience. Well I must say its a coincidence. Any way no objections, if you fell like that you can Report This Article.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
 |
|
 |
*throws down gauntlet*
I think multiple row selection would add some value, otherwise the code is pretty simple, but still nice. I voted a 4.
DR
|
|
|
|
 |
|
 |
Hi,
If you remove this check.
else if (previousRow != null)
document.getElementById(previousRow).style.backgroundColor = "#ffffff";
it will work for multiple rows as well. a slight change may require to deselect the rows in the first if check.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
 |
|
 |
Hi, you have done a good work and simple and easy javascript to implement. Have a nice day.
|
|
|
|
 |
|
 |
thanks.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
 |
|
 |
cool feature!!!
but i cant download your source code.
thanks
|
|
|
|
 |
|
 |
Hi, well I will try to reupload the code I am not sure why its not taking the file because at the time of writting this article I uploaded all the files and the zip file was there. Any way I will check again.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
 |