ASP.NET gridview中点击任意行的任意位置选中某行交替效果 变换鼠标手势,获取选定行的指写数据

ASP.NET2005 gridview中点击某行的任意位置选中某行 交替效果 变换鼠标手势

在 GridView中增加选择按钮SELECT,并让其不显示

<Columns>
<asp:CommandField ShowSelectButton="True" Visible="False" />
</Columns>
为gridview添加RowDataBound事件的代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
              //鼠标移动到每项时颜色交替效果
            e.Row.Attributes["onmouseover"]=      "e=this.style.backgroundColor;this.style.backgroundColor='#cccccc'";
            e.Row.Attributes["onmouseout"]= "this.style.backgroundColor=e";
            //设置悬浮鼠标指针形状为"小手"  
            e.Row.Attributes["style"] = "Cursor:hand";
            //鼠标点击某行即选中某行

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
        }
    }

//获取选定行的指写数据

    protected void GVData_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        try
        {
            currentNo = this.GVData.Rows[e.NewSelectedIndex].Cells[1].Text.ToString();
            currentItem = this.GVData.Rows[e.NewSelectedIndex].Cells[6].Text.ToString();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
   运行的时候可能会出现“invalid postback or callback argument”的错误提示,只要将aspx页面<%@ Page%>上加上属性 EnableEventValidation="false" 就可以了。
注:好多网上找的代码是这样的,不用能,大家注意,代码如下:
//单击行的任意列会自动选中此行,加在RowCreated事件中也可以
                 e.Row.Attributes.Add("onclick", "__doPostBack('GridView1','Select$" + e.Row.RowIndex + "')");
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值