In head Section of html pages
<script language=”javascript”>
function ChangeStyle(rowId, linkId)
{
switch (document.getElementById(linkId).innerHTML)
{
case “Select”:
document.getElementById(rowId).style.background = “#CCFFCC”;
document.getElementById(linkId).innerHTML = “DeSelect”;
break;
case “DeSelect”:
document.getElementById(rowId).style.background = “#FFFFFF”;
document.getElementById(linkId).innerHTML = “Select”;
break;
}
return false;
}
</script>
--------------------------------------------------
In RowDataBound of Gridview
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//refrence control inside gridview
LinkButton LinkButton1 = (LinkButton)e.Row.FindControl(“LinkButton1?);
//add onclick attributes to linkbutton
LinkButton1.Attributes.Add(“onclick”, “return ChangeStyle(‘” + e.Row.ClientID + “‘,'” + LinkButton1.ClientID + “‘)”);
}
}
LinkButton1.Attributes.Add(“onclick”, “return ChangeStyle(‘” + e.Row.ClientID + “‘,'” + LinkButton1.ClientID + “‘)”);
}
}
No comments:
Post a Comment