Asp.net 当用户单击下一行时,删除网格视图中的文本框属性

Asp.net 当用户单击下一行时,删除网格视图中的文本框属性,asp.net,gridview,Asp.net,Gridview,大家好,我已经编写了一个代码,在用户单击网格视图行时突出显示行颜色,以及文本框背景颜色。但我想在用户单击下一行时清除文本框的应用颜色 这是我为文本框添加颜色的代码 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { DataRowView drv = e.Row.DataItem as DataRowView; if (e.Row.RowType == DataControl

大家好,我已经编写了一个代码,在用户单击网格视图行时突出显示
行颜色
,以及
文本框背景颜色
。但我想在用户单击下一行时清除文本框的应用颜色

这是我为文本框添加颜色的代码

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>

//变量,该变量将存储上次单击行的id
var-previousRow;
函数ChangeRowColor(行,iEmpID)
{
//如果上次单击的行与当前单击的行相同
如果(上一行==行)
return;//什么也不做
//如果之前单击了行,则
else if(上一行!=null)
document.getElementById(previousRow).style.backgroundColor=“#ffffff”//将前一行的颜色改回白色
document.getElementById(行).style.backgroundColor=“#ffffda”;//将当前行的颜色更改为浅黄色
//location=“Default9.aspx”;
//将当前行id分配给要单击的下一行的上一行id
previousRow=行;
//document.getElementById('ctl00\u contentplaceholder 1\u HiddenField1')。value=iEmpID;
}
样本图像


您可以使用JQuery将单击处理程序附加到GridView中的每个文本输入区域,并管理处理程序中单元格和输入的样式


请参见以下示例:。

GridView控件呈现为表。从MSDN:
在表中显示数据源的值
。因此,所提供的示例(稍加修改)应提供您所需的功能。我知道如何处理网格视图模板,但正如您所说,在没有表格的情况下,如何使该功能适用于我