当前位置:编程学习 > C#/ASP.NET >>

gridview 单击行事件,求指导

我定义了一个gridview 叫gridview1,我想单击gridview一行的任意位置都能触发一个响应,该怎么做啊
具体:1.怎么实现单击行跳转页面,类似于126邮箱里面那个点击已发送邮件的一行会跳转到具体的已发送信息页面(而且跳转的页面是里一个页面的分页(freamset))
          2.怎么实现单击行设置一个该行的属性列的值,在其他页面也能获取到(类似于发送邮件时获取联系人邮箱一样)

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) //列表鼠标响应函数
    {

        //首先判断是否是数据行

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");

            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

            //设置悬浮鼠标指针形状为"小手"
            e.Row.Attributes["style"] = "Cursor:hand";
}
    }

是在这里面实现吗,我都纠结了好久了,求各位大侠解决啊,给点具体的关键代码啊 --------------------编程问答-------------------- 每次都没人啊 --------------------编程问答-------------------- 你可以写个JS了,然后在GridView1_RowDataBound这个事件中注册onclick事件了.
e.Row.Attributes.Add("onclick","JS事件") --------------------编程问答-------------------- JS里就是你要做的"跳转页面"事件 --------------------编程问答--------------------
引用 2 楼 weslonlovejall 的回复:
你可以写个JS了,然后在GridView1_RowDataBound这个事件中注册onclick事件了.
e.Row.Attributes.Add("onclick","JS事件")


正确的 --------------------编程问答--------------------
引用 2 楼 weslonlovejall 的回复:
你可以写个JS了,然后在GridView1_RowDataBound这个事件中注册onclick事件了.
e.Row.Attributes.Add("onclick","JS事件")


注册事件
--------------------编程问答-------------------- 直接在后台写可以吗
e.Row.Attributes.Add("onclick ", "window.open( 'ShowFriendInfo.aspx?deliver_id= " + e.Row.Cells[1].Text + " '); ");

但是这个e.Row.Cells[1].Text怎么貌似取不到值啊,还有用window.open怎么设置target咧 --------------------编程问答-------------------- 取值貌似用下面这个可以
string friendid = DataBinder.Eval(e.Row.DataItem, "user_id_friend").ToString();
但是我在跳转后的页面调试的时候,出错了,很诡异
 protected String getFriend(String userid, String friendid)
    {
            DB.UserFriendsDB info = new DB.UserFriendsDB();
            DataSet ds = new DataSet();
            ds= info.SelectByfriendId(userid, friendid);
            String friendname = ds.Tables[0].Rows[0][2].ToString();
            return friendname;
    }
对上段代码,我取到跳转前的传值friendid(确实取到了)作为这个函数的参数就出错了,但是如果直接将参数的值在这个页面设定,就没错,难道是跳转出错了????? --------------------编程问答-------------------- 已经解决了,我头昏了"window.open( 'ShowFriendInfo.aspx?deliver_id= " + e.Row.Cells[1].Text + " '); ");  deliver_id= 这个后面居然有个空格额 --------------------编程问答--------------------

类似open的
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,