25
2012
04

查询数据库并绑定到GridView

protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource sqlSource = new SqlDataSource(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString,
"SELECT * FROM [tb_ title] WHERE Title like '%@TitName%' and Info like '%@TeaName%';");

ControlParameter country = new ControlParameter();
country.Name = "Title";
country.Type = TypeCode.String;
country.ControlID = "TitleText";
country.PropertyName = "SelectedValue";

sqlSource.SelectParameters.Add(country);

country.Name = "Info";
country.Type = TypeCode.String;
country.ControlID = "InfoText";
country.PropertyName = "SelectedValue";

sqlSource.SelectParameters.Add(country);

Page.Controls.Add(sqlSource);

GridView1.DataSource = sqlSource;
GridView1.DataBind();
}
« 上一篇下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。