gridview绑定了记录,hyperlink 链接到 a.aspx页,我怎样做才能把 字段ID 的值传到a.aspx页。
解决方案 »
- DataList 怎么搞啊 ? 郁闷翻的咯!
- 用C#控制Repeater的HeaderTemplate、ItemTemplate?
- 使用SqlDataReader关闭连接的问题
- 运算时数字前面的0怎么才能让他不丢掉呢?
- 一个弱智的问题如何把SQL2000的datetime 字段中的时-分-秒去掉?
- 高兴贴:五一放假,散分.干半年了,该好好休息了,祝全都程序员.五一玩得开心
- 企业库读取数据错误
- 菜鸟提问!这样的Email发送功能怎么实现啊?加急!
- Visual Studio .Net MSDN 2003 帮助文件没有“Contents”、“Index”这两项
- 无法打开*.aspx ???
- 设置另一页面textbox控件的问题!
- 关于ASP.NET2.0下禁用ViewState
这样,我都是这样做的,成功
<Columns>
<asp:BoundField HeaderText="用户名" DataField="name" />
<asp:BoundField HeaderText="上传时间" DataField="uploadtime" />
<asp:HyperLinkField HeaderText="文件名" DataTextField="filename" NavigateUrl="FileDownLoad.aspx?id=<%#Eval("id")%>" />
</Columns>
</asp:GridView>
这样写报错
{ if (e.CommandName =="cd")
{
Response.Redirect("a.aspx?id="+e.CommandArgument+"");
}
}
gridview里有hyperlink列,有个字段ID和这一列绑定,我想点这一列后,把ID的值传给a.aspx这一页。
Literal content ('<asp:HyperLinkField HeaderText="文件名" DataTextField="filename" NavigateUrl="FileDownLoad.aspx?id=') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.
你的LinkButton 里面有两个属性一个是CommandName 这个可以判断你执行的是什么事件 CommandArgument这个绑定你想获取的字段值
下面是后台RowCommand 事件里的判断
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{ if (e.CommandName =="你在LinkButton按钮里面CommandName设置的值")
{
Response.Redirect("a.aspx?id="+e.CommandArgument+"");
}
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="uid" HeaderText="uid" InsertVisible="False" ReadOnly="True"
SortExpression="uid" />
<asp:BoundField DataField="userName" HeaderText="userName" SortExpression="userName" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text="Search"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:netConnectionString %>"
SelectCommand="SELECT [uid], [userName] FROM [users]"></asp:SqlDataSource>
代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink hl = e.Row.Cells[2].FindControl("HyperLink1") as HyperLink;
if (hl != null)
{
hl.NavigateUrl = "~/Search.aspx?uid=" + e.Row.Cells[0].Text;
}
}
}search页面:
if (!IsPostBack)
{
if (Request["uid"] != null)
{
this.Label1.Text = Request["uid"].ToString();
}
}
这放在哪里,放在模板页里面怎么报错呀 <asp:TemplateField>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="dg" CommandArgument=' <%# Eval("ProductID") %>'>【订购】 </asp:LinkButton>
</asp:TemplateField>
grideddddddddd
DataTextField="au_lname" HeaderText="连接" />
这个方法比较简单。e.CommandName 这个方法也可以实现。