如何在if (!Page.IsPostBack)里写这个方法
我想在if(!Page.IsPostBack)里调用这个方法,protectedvoidpage_onclick(Objectsender,CommandEventArg...
我想在if (!Page.IsPostBack)里调用这个方法,
protected void page_onclick(Object sender, CommandEventArgs e)
可是这个方法是带参数的。我不会写
page_onclick()括号里应该填什么呢?
需要调用的代码
protected void page_onclick(Object sender, CommandEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open();
string cmdtext = "select * from [order] where game = '" + e.CommandName + "' union all select * from [order] where game <> '" + e.CommandName + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
} 展开
protected void page_onclick(Object sender, CommandEventArgs e)
可是这个方法是带参数的。我不会写
page_onclick()括号里应该填什么呢?
需要调用的代码
protected void page_onclick(Object sender, CommandEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open();
string cmdtext = "select * from [order] where game = '" + e.CommandName + "' union all select * from [order] where game <> '" + e.CommandName + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
} 展开
2个回答
展开全部
你啊.这么来写:
public void dataBind(){
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open();
string cmdtext = "select * from [order] where game = '" + e.CommandName + "' union all select * from [order] where game <> '" + e.CommandName + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
然后在你的其它事件里直接调用这个方法就OK了:
protected void page_onclick(Object sender, CommandEventArgs e)
{
dataBind();
}
同样的道理.在page_load里也这么调:
if(!this.IsPostBack){
dataBind();
}
public void dataBind(){
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
con.Open();
string cmdtext = "select * from [order] where game = '" + e.CommandName + "' union all select * from [order] where game <> '" + e.CommandName + "' ";
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
然后在你的其它事件里直接调用这个方法就OK了:
protected void page_onclick(Object sender, CommandEventArgs e)
{
dataBind();
}
同样的道理.在page_load里也这么调:
if(!this.IsPostBack){
dataBind();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询