GridView绑定问题

magicbacon 2009-04-10 02:01:09
各位,我想在GridView的数据行中加一个Button,用来弹出一个窗口,用于选择并回传数据,我想在URL后加上该数据行的行数作为参数,我是这样写的

<asp:Button ID="Button1" runat="server" Text="..." OnClientClick="window.open('a.aspx?ID=<%# Container.DataItemIndex + 1 %>')"


(意图应该很明显吧 :) )不幸的是,这样写是不可行的,请问这里应该怎么改呢?或者有什么替代方法?注意我是想在弹出窗口中选择内容回传的~
...全文
207 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
magicbacon 2009-04-10
  • 打赏
  • 举报
回复
按7楼做法修改通过~
阿非 2009-04-10
  • 打赏
  • 举报
回复

OnClientClick=<%# "window.open('a.aspx?ID="+(Container.DataItemIndex + 1).ToString()+"')"%>

or

OnClientClick='<%# "window.open(\"a.aspx?ID="+(Container.DataItemIndex + 1).ToString()+"\")"%>'
leexhen 2009-04-10
  • 打赏
  • 举报
回复
Button1.Attributes.Add("onclick","window.open('a.aspx?ID=ID值')")
用这个方法才能调用JS脚本
koukoujiayi 2009-04-10
  • 打赏
  • 举报
回复
改OnClientClick为OnClick试试!!
<asp:Button ID="Button1" runat="server" Text="..." OnClick="javascript:window.open('a.aspx?ID= <%# Container.DataItemIndex + 1 %>')"
koukoujiayi 2009-04-10
  • 打赏
  • 举报
回复
改OnClientClick为OnClick试试!!
<asp:Button ID="Button1" runat="server" Text="..." OnClick="window.open('a.aspx?ID=<%# Container.DataItemIndex + 1 %>')"
makun0624 2009-04-10
  • 打赏
  • 举报
回复
OnClientClick="javascript:window.open('a.aspx?ID=<%# Container.DataItemIndex + 1 %>‘)
zzxap 2009-04-10
  • 打赏
  • 举报
回复
[code=HTML]
asp.net单击gridview或button弹出新窗口实现方法
2007-09-05 12:02 P.M.
先是父页面
<form id="form1" runat="server">       
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="CityID" DataSourceID="AccessDataSource1" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="CityID" HeaderText="CityID" InsertVisible="False" ReadOnly="True" SortExpression="CityID" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="provinceID" HeaderText="provinceID" SortExpression="provinceID" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/test.mdb" SelectCommand="SELECT * FROM [CityTable]"></asp:AccessDataSource>
</form>

===================================
public partial class CSDN_webform1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
e.Row.Attributes.Add("onclick", "window.showModalDialog('webform3.aspx?index="+(e.Row.RowIndex+1).ToString()+"&gridid="+this.GridView1.ClientID+"');");
}
}
}

子页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="webform3.aspx.cs" Inherits="CSDN_webform3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<base target="_self" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
============================================
public partial class CSDN_webform3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Request.QueryString["index"]);
}
protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(typeof(string), "","<script>parent.document.forms[0].submit();window.close();</script>");
}
}


上面是在网上找的方法,试过了,好用的,这种方法关闭子窗口时会刷新父页面,如果不想刷新父页面,可以把子页面放框架页里,步骤是新建一个页面,把<body>部分去掉,添入html代码如下:

<head runat="server">
<title>无标题页</title>
</head>
<frameset rows="0,*">
<frame src="about:blank">
<frame src="*.aspx"><!--*为子页名-->
</frameset>
</html>
调用时把父页面的蓝色字部分换成框架页名就行了,而且这种方法也支持在子页面响应服务器事件,如button等.就是传值比较麻烦,我曾用的方法是如下
在父页面的加载事件中写:
ClientScriptManager csm = Page.ClientScript;
if (!csm.IsClientScriptBlockRegistered("clientScript"))
{
String strScript = "<script>\r\n";
strScript += "function OpenWin(){\r\n";
strScript += "var str=window.showModalDialog('frm_frame.aspx',document.Form1.Hidden1.value)\r\n";
//strScript += "if(str!=null) document.Form1.Hidden1.value=str\r\n";
strScript += "}\r\n";
strScript += "</script>";
csm.RegisterClientScriptBlock(this.GetType(), "clientScript", strScript);
}
btnEdit.Attributes.Add("onclick", "OpenWin()");
//电击btnEdit,弹出子窗体
子页面:
MyBody.Attributes.Add("onload", "document.form1.TextBox1.value=window.parent.dialogArguments");
这样子页面TextBox1就可以显示父页面Hidden1的值了.
[/CODE]
vlysses 2009-04-10
  • 打赏
  • 举报
回复
应在模板列中加入html的button,如下:
<input type="button" ID="Button1" Text="..." OnClick="javascript:var sRe=window.showModalDailog('a.aspx?id=<%# Eval("Index") %>','','')"
xiaoqhuang 2009-04-10
  • 打赏
  • 举报
回复
有runat=server, 必须整个OnClientClick的值是个string
如果只弹出用可用html button
xiaoqhuang 2009-04-10
  • 打赏
  • 举报
回复
OnClientClick='<%#"window.open(\"a.aspx?id="+Container.ItemIndex.ToString() +"\");" %>'
helimin19 2009-04-10
  • 打赏
  • 举报
回复
<asp:Button ID="Button1" runat="server" Text="..." OnClientClick="javascript:window.open('a.aspx?ID='+this.nextSibling.value)" /><input type="hidden" value="<%# Container.DataItemIndex + 1 %>" />
messi_yang 2009-04-10
  • 打赏
  • 举报
回复
頂一下~~
koukoujiayi 2009-04-10
  • 打赏
  • 举报
回复
这种功能微软的AJAx中的ModalPopupExtender控件就是针对这样一种功能做的!!
chouto 2009-04-10
  • 打赏
  • 举报
回复
用模态窗口行不? window.returnValue

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧