郑德才博客 记录学习,记录工作,学习知识分享!

查询数据库并绑定到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();
}
2012年4月25日 | 发布:郑德才博客 | 分类:学习之路 | 评论:0

发表留言: