我要实现gridview某行被选中时他的背景颜色不是蓝色,怎么实现?

解决方案 »

  1.   

     前台用一个BUTTON隐藏:
    <asp:TemplateField HeaderText="单据编号" >
                        <ItemTemplate>                        <asp:Button ID="btnHiddenPostButton" CommandName="HiddenPostButtonCommand" runat="server" Text="" style="display:none" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None" ForeColor="Transparent" />
                          </ItemTemplate>
                        <ItemStyle Width="100px" />
                         </asp:TemplateField>后台RowDataBound方法里控制颜色就行:
    protected void gvUserLeave_RowDataBound(object sender, GridViewRowEventArgs e)
        {
                Button btnHiddenPostButton = e.Row.FindControl("btnHiddenPostButton") as Button;            if (btnHiddenPostButton != null)
                {
                    e.Row.Attributes["onclick"] = String.Format("javascript:document.getElementById('{0}').click()", btnHiddenPostButton.ClientID);            }
        }
      

  2.   

    是不是这个意思?选中某行,给这行个颜色(鼠标滑过):protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='purple'");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");                e.Row.Attributes.Add("onclick", "javascrpit:window.open('XXX.aspx?xxx=" + e.Row.Cells[1].Text  + "&TaskName=" + e.Row.Cells[2].Text + "')");
                }
      

  3.   

    搜索
    gridview72般绝技  水清月儿