objectdatasource ,textbox,点击按钮查询问题
我想在文本框中输入关键子,点击按钮查询,请问这个该怎么实现,谢谢,我是如下写的:
public class Tsqlope
{
private SqlConnection conn;
private String connstr;
private SqlCommand sqlcommend;
private SqlDataReader sqlreader;
private DataSet sqldataset;
private SqlDataAdapter sqladapter;
public Tsqlope()
{
//
// TODO: 在此处添加构造函数逻辑
//
connstr = ConfigurationManager.ConnectionStrings[ "jwglConn "].ConnectionString;
conn = new SqlConnection(connstr);
sqlcommend = new SqlCommand();
sqladapter = new SqlDataAdapter();
sqldataset = new DataSet();
}
public DataSet Tdataset(String querystr)
{
sqladapter.SelectCommand = new SqlCommand(querystr, conn);
sqladapter.Fill(sqldataset, "temp ");
return sqldataset;
}
web中是这样:
<asp:ObjectDataSource ID= "ObjectDataSource1 " runat= "server " SelectMethod= "Tdataset "
TypeName= "Tsqlope ">
<SelectParameters>
<asp:Parameter DefaultValue= "select * from class_tabl " Name= "querystr " Type= "String " />
</SelectParameters>
</asp:ObjectDataSource>
点击按钮部分不知该怎么写了,请各位帮忙,谢谢
------解决方案--------------------如果你不用objectdatasource的特性的话,依据你现在的代码没必要使用
------解决方案--------------------按钮点击代码可以
Tsqlope();
DataGrid1.DataSource = Tdataset(你的sql语句);
DataGrid1.DataBind();
这样就可以了
------解决方案--------------------帮顶
------解决方案--------------------LZ的写法不符合objectDataSource的规范,也不利于使用objectDataSource的特性