如何在双击后得到gridview中对应的记录? 功能很简单:就是点击列表中的一条记录,弹出一个新的web窗体,显示该单子的明细,查了几个帖子,说了需要结合JavaScript来做,但是没有说如何在处理代码中获取JavaScript所获取的记录信息,我刚入门,希望大家能给一个完整的过程谢谢。没分了,是在对不住啊。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是一个双击事件吗?页面用(window.ShowModalDialog)弹出后返回一个值给父页面就好了啊! 在给gridview邦定记录的时候给每一行添加onclick事件的,string id = "";e.Row.Attributes.Add("onclick", "showDetail('"+id+"');");前台加个showDetail的函数的function showDetail(id){window.showDialog("detail.aspx?id" + id);} 用HyperlinkField列也可以实现你的功能,将girdview中的列设为以下格式:<asp:HyperLinkField DataNavigateUrlFormatString="~/detail/detDetailAll.aspx?programerID={0}&openFlag=0" DataTextField="programerName" HeaderText="课题名称" SortExpression="programerName" DataNavigateUrlFields="programerID" ><ItemStyle HorizontalAlign="Left" /></asp:HyperLinkField> protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e) { //为表格添加数字列 if (e.Row.RowIndex != -1) { int id = e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); } if (e.Row.RowType == DataControlRowType.DataRow) { //添加删除确认 ((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除数据吗?')"); ((LinkButton)(e.Row.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('确定永久删除数据吗?')"); //鼠标经过表格行改变颜色 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange';this.style.color='buttontext';this.style.cursor='default';"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';"); //鼠标双击跳转到编辑页面 e.Row.Attributes.Add("ondblclick", "[location.href='DepartmentAdd.aspx?TYPE=VIEW&ID=" + e.Row.Cells[4].Text + "']此处改成你要的操作并把ID传进去不就行了吗"); } } 在GridView中定义双击的js函数,如下: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("ondblclick", "test("+e.Row.RowIndex.ToString()+")"); } }js: function test(n) { alert(n);//获得点击的行数 ..................... } protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e) { //为表格添加数字列 if (e.Row.RowIndex != -1) { int id = e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); } if (e.Row.RowType == DataControlRowType.DataRow) { //添加删除确认 ((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除数据吗?')"); ((LinkButton)(e.Row.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('确定永久删除数据吗?')"); //鼠标经过表格行改变颜色 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange';this.style.color='buttontext';this.style.cursor='default';"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';"); //鼠标双击跳转到编辑页面 e.Row.Attributes.Add("ondblclick", "[location.href='DepartmentAdd.aspx?TYPE=VIEW&ID=" + e.Row.Cells[4].Text + "']此处改成你要的操作并把ID传进去不就行了吗"); } } e.Row.Attributes.Add("ondblclick", "[location.href='DepartmentAdd.aspx?TYPE=VIEW&ID=" + e.Row.Cells[4].Text + "']此处改成你要的操作并把ID传进去不就行了吗");谢谢楼上,请问如果要弹出新页面,并给新页面中的三个label赋值(对应GridView的3个字段),该如何做呢? 呵呵,能想来,我自己都觉得有些无奈,不过确实不理解。以前一直用Delphi,最近才学习web开发,很多地方脑子都转不过来,大家见笑了不过笑归笑,还望帮在下解决问题啊,呵呵 说实话,我也是初学者,又那么巧我完成了上面的功能。因为不方便贴代码。以下列出一些关键字,你可以去搜索下,网上都是现成的。1、首先构造能传送的id,获取id,然后弹出页面。你可以参考4楼的说法,这里面涉及到window.ShowModalDialog 的用法,至于你说的要带3个参数,这里可以用session的方法也可以用地址带参数的方法(比如www.abc.com/a.aspx?a=1&b=2&c=3)2、然后弹出的的页面获取参数如果用session的方法就是HttpContext.Current.Session["a"].ToString.Trim()如果是用参数的方法就是HttpContext.Current.QueryString["id"]3、至于赋值嘛?label1.text = a这个应该没什么问题吧?大概方法是如此了,看上去挺简单,不过如果不懂得话还是逐个击破难点吧。GL 你可能会用到的一些搜索关键字,其实很多问题网上都有现成的了,只是看你如何搜索而已,实在没有再来提问吧,window.ShowModalDialogsession网页 传递参数jsgridview 获取点击行 id 在GridView的RowDataBound事件中e.Row.Attributes.Add("onclick", "弹窗函数"); 好简单的问题:如何实现点击gridview的某行,在image里显示图片? 网站安全问题 类型“ltaoshaWeb.App_Code.wode”同时存在于“c:\Users\zhl\AppData\Local\Temp\Temporary ASP. 连接不上 sqlserver2005 求教网页后台管理 哪位朋友帮我解释一下这条脚本语句的 意思,谢谢 虚心请教用VS。NET如何打开远程的项目 请问在VS中如何引用命名空间? 请教各位高手 困扰很久的问题 如何单独为gridview中特定行列中文字添加超链 【感谢国家】需要一个能过滤JS块的代码,谢谢。可以用就结贴。在线。
string id = "";
e.Row.Attributes.Add("onclick", "showDetail('"+id+"');");前台加个showDetail的函数的
function showDetail(id)
{
window.showDialog("detail.aspx?id" + id);
}
<asp:HyperLinkField DataNavigateUrlFormatString="~/detail/detDetailAll.aspx?programerID={0}&openFlag=0" DataTextField="programerName" HeaderText="课题名称" SortExpression="programerName" DataNavigateUrlFields="programerID" >
<ItemStyle HorizontalAlign="Left" />
</asp:HyperLinkField>
{
//为表格添加数字列
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
} if (e.Row.RowType == DataControlRowType.DataRow)
{
//添加删除确认
((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除数据吗?')");
((LinkButton)(e.Row.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('确定永久删除数据吗?')"); //鼠标经过表格行改变颜色 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange';this.style.color='buttontext';this.style.cursor='default';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';"); //鼠标双击跳转到编辑页面 e.Row.Attributes.Add("ondblclick", "[location.href='DepartmentAdd.aspx?TYPE=VIEW&ID=" + e.Row.Cells[4].Text + "']此处改成你要的操作并把ID传进去不就行了吗");
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "test("+e.Row.RowIndex.ToString()+")");
}
}js:
function test(n) {
alert(n);//获得点击的行数
.....................
}
{
//为表格添加数字列
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
} if (e.Row.RowType == DataControlRowType.DataRow)
{
//添加删除确认
((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除数据吗?')");
((LinkButton)(e.Row.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('确定永久删除数据吗?')"); //鼠标经过表格行改变颜色 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange';this.style.color='buttontext';this.style.cursor='default';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';"); //鼠标双击跳转到编辑页面 e.Row.Attributes.Add("ondblclick", "[location.href='DepartmentAdd.aspx?TYPE=VIEW&ID=" + e.Row.Cells[4].Text + "']此处改成你要的操作并把ID传进去不就行了吗");
}
}
以前一直用Delphi,最近才学习web开发,很多地方脑子都转不过来,大家见笑了
不过笑归笑,还望帮在下解决问题啊,呵呵
1、首先构造能传送的id,获取id,然后弹出页面。
你可以参考4楼的说法,这里面涉及到window.ShowModalDialog 的用法,至于你说的要带3个参数,这里可以用session的方法也可以用地址带参数的方法(比如www.abc.com/a.aspx?a=1&b=2&c=3)
2、然后弹出的的页面获取参数
如果用session的方法就是HttpContext.Current.Session["a"].ToString.Trim()
如果是用参数的方法就是HttpContext.Current.QueryString["id"]
3、至于赋值嘛?
label1.text = a这个应该没什么问题吧?大概方法是如此了,看上去挺简单,不过如果不懂得话还是逐个击破难点吧。GL
window.ShowModalDialog
session
网页 传递参数
js
gridview 获取点击行 id
e.Row.Attributes.Add("onclick", "弹窗函数");