【发布时间】:2015-08-01 17:02:05
【问题描述】:
我一直在努力寻找解决方案,但仍然没有什么好办法。
我从后面的代码(以及 SqlDataSource)创建了一个 GridView。在我的页面中有一个 DropDownList 填充了用户名(填充在后面的代码中)。
当我在 DDL 中选择用户名时,GridView 应该重新绑定并仅显示属于该特定用户的数据。由于某种原因,我无法让它工作,我不明白为什么。
这是我的代码:
GW和SqlDS的创建:
SqlDataSource SqlDataSourceFormulariDaAppr = new SqlDataSource();
SqlDataSourceFormulariDaAppr.ID = "SqlDataSourceFormulariDaAppr";
this.Page.Controls.Add(SqlDataSourceFormulariDaAppr);
SqlDataSourceFormulariDaAppr.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlDataSourceFormulariDaAppr.SelectCommand = "Query";
SqlDataSourceFormulariDaAppr.SelectParameters.Add("userID", DropDownListUtenti.SelectedValue);
SqlDataSourceFormulariDaAppr.DataBind();
GridViewFormulariDaAppr.DataSource = SqlDataSourceFormulariDaAppr;
GridViewFormulariDaAppr.DataBind();
SelectedIndex 方法:
protected void DropDownListUtenti_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewFormulariDaAppr.DataBind();
}
任何帮助将不胜感激。
【问题讨论】:
-
你在 page_load 中写了什么。你在检查 !Page.IsPostBack 加载吗
-
if (!IsPostBack) { populateGrid();我的 Page_Load 中有这个,我调用方法来创建 GW 和 SqlDS。
-
在填充 DDL 之前,您必须检查 Page.IsPostBack。请检查
-
请在此处编写您的页面加载代码
-
受保护的 void DropDownListUtenti_SelectedIndexChanged(object sender, EventArgs e) { populateGrid(); }