vs2005中 gridview是在前台数据绑定的,在后台的查询按钮事件中,怎么写代码?我用之前的VS2003中的代码显示的提示是数据源冲突,请高手指点~多谢
string sort = Request.Form["bigclass"];
string pname = Request.Form["pname"]; string he = "Select *,(innum-salenum-retnum) as intnum from inventorys where 1=1";
if (sort != "")
{
he += "and bigcla='" + sort + "'";
}
if (pname != "")
{
he += "and pname='" + pname + "'";
}
string strcon = ConfigurationManager.ConnectionStrings["mConnectionString"].ConnectionString;
SqlConnection objcon = new SqlConnection(strcon);
objcon.Open();
DataSet ds = new DataSet();
try
{
SqlDataAdapter adapter = new SqlDataAdapter(he, objcon);
adapter.Fill(ds, "inventorys");
GridView1.DataSource = ds.Tables["inventorys"].DefaultView;
GridView1.DataBind(); int startIndexs;
startIndexs = ds.Tables[0].DefaultView.Count; objcon.Close();//
}
catch
{
Response.Write("<script language='javascript'> alert('因您网络速度过慢,请稍后再试!');</script>");
}
string sort = Request.Form["bigclass"];
string pname = Request.Form["pname"]; string he = "Select *,(innum-salenum-retnum) as intnum from inventorys where 1=1";
if (sort != "")
{
he += "and bigcla='" + sort + "'";
}
if (pname != "")
{
he += "and pname='" + pname + "'";
}
string strcon = ConfigurationManager.ConnectionStrings["mConnectionString"].ConnectionString;
SqlConnection objcon = new SqlConnection(strcon);
objcon.Open();
DataSet ds = new DataSet();
try
{
SqlDataAdapter adapter = new SqlDataAdapter(he, objcon);
adapter.Fill(ds, "inventorys");
GridView1.DataSource = ds.Tables["inventorys"].DefaultView;
GridView1.DataBind(); int startIndexs;
startIndexs = ds.Tables[0].DefaultView.Count; objcon.Close();//
}
catch
{
Response.Write("<script language='javascript'> alert('因您网络速度过慢,请稍后再试!');</script>");
}
<asp:TextBox id="pname" runat="server" />
<asp:Button .... OnClick="btnSearch_Click" />
protected void btnSearch_Click(object:sender,EventArg:string)
{
string sort = 页面控件的值
string pname = pname.Text;
后面代码一样了
}
兄弟,你说的这个我知道,我问的是前台手工配好的GRIDVIEW,在后台怎么写用文本框里的值来写查询语句数据源的代码
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mConnectionString %>"
SelectCommand="Select *,(innum-salenum-retnum) as intnum from inventorys where 1=1">
</asp:SqlDataSource>后台在查询按钮中,这个数据源该如何写?
个人观点,我也是菜鸟