当前位置: 代码迷 >> ASP.NET >> 请教datagrid模板中<asp:hyperlink>或<a>怎样带参数传值到另一页
  详细解决方案

请教datagrid模板中<asp:hyperlink>或<a>怎样带参数传值到另一页

热度:10822   发布时间:2013-02-26 00:00:00.0
请问datagrid模板中<asp:hyperlink>或<a>怎样带参数传值到另一页?
我想将参数传到play.aspx里的src属性实现播放功能.
但怎样实现传值?请诸位帮我调通这个东西!
default.aspx
<%@Import   Namespace= "System.Data "   %>
<%@Import   Namespace= "System.Data.SqlClient "   %>
<html> <head> <title> DataGrid </title> </head>
<body>
<form   id= "form1 "     method=post     runat=server>
<asp:DataGrid   ID= "DataGrid1 "   runat=server   AutoGenerateColumns= "false "   >
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
          <asp:HyperLink   runat=server     ID= "LinkButton1 "       NavigateUrl= "~/play.aspx "  
          Text= ' <%#DataBinder.Eval(Container, "DataItem.Text ")%> '>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>

<script   runat=server     language= "C# ">
void   Page_Load(Object   sender,EventArgs   e)
{        
        SqlConnection   SqlConnection1=new   SqlConnection( "server=localhost;user   id=sa;password=;database=database1; ");
        SqlDataAdapter   SqlDataAdapter1=new   SqlDataAdapter( "Select   *   from   table2 ",SqlConnection1);
        DataSet   DataSet1=new   DataSet(   );
        SqlDataAdapter1.Fill(DataSet1);
        DataGrid1.DataSource=DataSet1;
        DataGrid1.DataBind(   );
}
</script>
-------------------------------------------
被传值页面:play.aspx
<html>
<head>
<title> 你好 </title>
</head>
<body>
<embed   id= "embed1 "     src=Requeset.QueryString[ "path "]     width=500     height=500>   </embed>  
</body>
</html>
-----------------------------------------------
数据库表:table2
path                                                             |         Text        
E:\火影\火影忍者TV版1-55\01.rmvb     |         火影第一集  
E:\火影\火影忍者TV版1-55\02.rmvb     |         火影第二集
E:\火影\火影忍者TV版1-55\03.rmvb     |         火影第三集
E:\火影\火影忍者TV版1-55\04.rmvb     |         火影第四集
-----------------------------------------------------




------解决方案--------------------------------------------------------
<asp:HyperLink runat=server ID= "LinkButton1 " NavigateUrl= "~/play.aspx?参数 "
Text= ' <%#DataBinder.Eval(Container, "DataItem.Text ")%> '>

------解决方案--------------------------------------------------------
<asp:HyperLinkColumn DataNavigateUrlField= "userid " DataNavigateUrlFormatString= "userlist.aspx?userid={0} "
DataTextField= "username " HeaderText= "111 "> </asp:HyperLinkColumn>
  相关解决方案