Привет всем, у меня есть написанный код, чтобы выделить Row colour
, а также text-box back ground colour
, когда пользователь нажимает на строку вида сетки. Но я хотел бы очистить примененный цвет для текстового поля, когда пользователь нажимает на следующую строку.
Это мой код для добавления цвета в текстовое поле
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
int iEmpID = Convert.ToInt32(drv["ID"]);
//e.Row.Attributes.Add("ondblclick", "location='cliMaintainEEpersonaldetails.aspx?EmpID=" + iEmpID + "'");
TextBox txb = (TextBox)e.Row.Cells[0].FindControl("lbl");
if (txb.Text == string.Empty)
{
e.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" + e.Row.ClientID + "','" + iEmpID + "')");
//txb.Attributes.Add("onclick", "document.all['" + e.Row.ClientID + "'].style.backgroundColor = ''red';");
txb.Attributes.Add("onclick", "this.previous_color=this.style.backgroundColor;this.style.backgroundColor='#ffffda'");
//txb.Attributes.Add("onmouseout", "this.style.backgroundColor=this.previous_color;");
}
}
}
Или я могу написать для этого функцию java-скрипта или возможно внести какие-либо изменения в существующий скрипт.
Это мой сценарий
<script type="text/javascript">
//variable that will store the id of the last clicked row
var previousRow;
function ChangeRowColor(row,iEmpID)
{
//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)
document.getElementById(previousRow).style.backgroundColor = "#ffffff"; //change the color of the previous row back to white
document.getElementById(row).style.backgroundColor = "#ffffda"; //change the color of the current row to light yellow
//location="Default9.aspx";
//assign the current row id to the previous row id for next row to be clicked
previousRow = row;
//document.getElementById('ctl00_ContentPlaceHolder1_HiddenField1').value = iEmpID ;
}
</script>
Примеры изображений
![enter image description here](https://i.stack.imgur.com/RNrQI.jpg)
![enter image description here](https://i.stack.imgur.com/3rNzF.jpg)