C# code<asp:TemplateField>
<ItemTemplate>
<table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="index.aspx?game=<%# Eval("game") %>" onclick="titlelink"><%# DataBinder.Eval(Container.DataItem,"game") %></a></td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
游戏名称
</HeaderTemplate>
</asp:TemplateField>后台程序页面
C# codeprivate void titlelink()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open(); string title = Request["game"].ToString(); //获取前台点击game字段的值 ,然后放到下面的select里面。
string cmdtext = "select * from [order] where game = '" + title + "'"; SqlCommand cmd = new SqlCommand(cmdtext, con);
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds, "[order]");
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
con.Close(); }这是一个朋友贴出的一段代码,具体什么意思差不多明白,想请各位帮忙找下错误,小弟不才,不能帮这位兄弟,还请大家帮忙!
<ItemTemplate>
<table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="index.aspx?game=<%# Eval("game") %>" onclick="titlelink"><%# DataBinder.Eval(Container.DataItem,"game") %></a></td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
游戏名称
</HeaderTemplate>
</asp:TemplateField>后台程序页面
C# codeprivate void titlelink()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open(); string title = Request["game"].ToString(); //获取前台点击game字段的值 ,然后放到下面的select里面。
string cmdtext = "select * from [order] where game = '" + title + "'"; SqlCommand cmd = new SqlCommand(cmdtext, con);
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds, "[order]");
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
con.Close(); }这是一个朋友贴出的一段代码,具体什么意思差不多明白,想请各位帮忙找下错误,小弟不才,不能帮这位兄弟,还请大家帮忙!
<a href="index.aspx?game= <%# Eval("game") %>" onclick="titlelink">
string title =Request.QueryString["game"].ToString();
有錯誤。
正確寫法:
<a href=‘index.aspx?game= <%# Eval("game") %>’ onclick="titlelink">
html链接能够调用c#方法吗? onclick="titlelink"C# codeprivate void titlelink()
<ItemTemplate>
<table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> <a href='index.aspx?game= <%# Eval("game") %>' onclick="titlelink"> <%#Eval("game") %> </a> </td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
游戏名称
</HeaderTemplate>
</asp:TemplateField>
后台程序页面
C# codeprivate void titlelink()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open(); string title = "";
if(Request.QueryString["game"]!=null)
{
title =Request.QueryString["game"].ToString(); //获取前台点击game字段的值 ,然后放到下面的select里面。
}
string cmdtext = "select * from [order] where game = '" + title + "'"; SqlCommand cmd = new SqlCommand(cmdtext, con);
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds, "[order]");
this.GridView1.DataSource = ds.Tables["order"];
this.GridView1.DataBind();
con.Close(); }
this.GridView1.DataSource = ds.Tables["order"]; //数据源是表(数据集ds中的表"order")