我在game字段那里写了个titlelink方法, 通过点击获得值。然后根据值在排序gridview ,但是运行以后点击没有任何反应 ,不知道哪里错了 前台页面<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>后台程序页面private 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>后台程序页面private 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(); }
http://blog.csdn.net/wanghr74/archive/2007/04/02/1549163.aspx,以及这个页面上的Scott Mitchell 的ASP.NET 2.0数据教程之六:: 编程设置ObjectDataSource的参数值,等等。不要写那个“this.GridView1.DataBind();”,使用asp.net2.0的数据绑定控件自动地支持数据绑定和数据更新流程,你的代码应该做高级的动作。底层的东西,自己不了解时手写太多容易走入死胡同,应该交给已经测试完善的组件去完成。
应该这样写?
还有sp1234大哥说的最好一句也有问题,建议先回去看下基础知识!