Click here to Skip to main content
15,897,090 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a javascript to get keyvalue of row selected by user in gridview.. now, i wanted to change the background color of row selected by user based on primary key... How can I do so...
Posted
Comments
Karthik_Mahalingam 11-Jan-14 5:10am    
post your code..
Codes DeCodes 12-Jan-14 4:58am    
protected void GridViewJobList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string primaryKey = DataBinder.Eval(e.Row.DataItem, "Entry_No") + "";
string jobNo = DataBinder.Eval(e.Row.DataItem, "Source_ID") + "";
string lineNo = DataBinder.Eval(e.Row.DataItem, "Line_No") + "";
e.Row.Attributes.Add("onclick", "opennewwindow('" + primaryKey + "','" + jobNo + "','" + lineNo + "')");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#6699FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F9F7F7'");

//e.Row.Attributes.Add("onclick", "ChangeRowColor(this)");
string primarykey1 = (Request.QueryString["primarykey"]);
//if (e.Row.DataItem, p)
//{
// e.Row.BackColor = System.Drawing.Color.Blue;
//}
if (primarykey1 != null)
{

if (primarykey1 == primaryKey)
{
e.Row.BackColor = System.Drawing.Color.Red;
}

}
}
}


on aspx page
var opennewwindow = function (primarykey ,jobNo,lineNo) {
window.location = "MechanicsJobTime.aspx?primarykey=" + primarykey + "&jobNo=" + jobNo + "&lineNo="+ lineNo;
}

man this works but as user clicks on another row.. key value of that row is taken but that particular row is not highlighted to red.

1 solution

Refer here
http://patelshailesh.com/index.php/change-background-color-of-row-of-gridview[^]
I hope this would help you to resolve this issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900