关于dropdownlist如何控制gridview显示内容的
我这里有两个表 表1中字段为username password qx bm bz 表2字段为bm我通过accessdatasource使dropdownlist这个控件与表2关联上了
同样使gridview与表1关联上了在设置accessdatasource时使用了条件Where bm='"+dropdownlist1.text+"'
这样做了之后我只能得刚开始进入页面时gridview表的值,当改变dropdownlist1内容时页面没有反应
请教怎么才能做到使用一个dropdownlist控件控制gridview显示内容啊 --------------------编程问答-------------------- 在列表改变事件里掉填充gridview的方法! --------------------编程问答-------------------- EnablePostBack 设置为TRUE --------------------编程问答-------------------- 你的第二个AccessDataSource关联应该是:
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="xxxxxxxxx.mdb"
SelectCommand="SELECT * FROM [表名] WHERE ([bm] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="bm"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters> </asp:AccessDataSource>
当然DropDownList要设置AutoPostBack为true --------------------编程问答-------------------- protected void DropDownListSchool_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (string.IsNullOrEmpty(DropDownListSchool.SelectedValue)) {
AccessDataSourceGridView.SelectParameters.Clear();
AccessDataSourceGridView.SelectCommand = "SELECT ...";
}
}
ConnectionString="connectionString"
ProviderName="providerName"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products] WHERE ([CategoryID] = ?)">
<SelectParameters>
<asp:ControlParameter Type="Int32"
Name="CategoryID"
ControlID="categoriesDDL"
PropertyName="SelectedValue" />
</SelectParameters>
--------------------编程问答-------------------- (1)AutoPostBack="True"
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>
(2)事件也注册了
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
(3)事件也写了
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
[align=left]
{
Response.Write(this.DropDownList1.SelectedItem);
}
怎么还是不能输出选定项?进行调试发现不能进入SelectedIndexChanged事件。
其实还有一种可能,就是你为DropDownList的不同option设置了相同的value
比如后台这么写:
if(!IsPostBack)
{
for(int i=0;i<10;i++)this.DropDownList1.Items.Add(new ListItem(i.ToString(),"same_value"));
}
这样不会触发SelectedIndexChanged事件,修改成
if(!IsPostBack)
{
for(int i=0;i<10;i++)this.DropDownList1.Items.Add(new ListItem(i.ToString(),i.ToString()));
}
一切些正常,根据msdn的解释:
ListControl.SelectedIndexChanged 事件
当列表控件的选定项在信息发往服务器之间变化时发生
这不同于js的onchange事件,改为
if(!IsPostBack)
{
for(int i=0;i<10;i++)this.DropDownList1.Items.Add(new ListItem(i.ToString(),"same_value"));
this.DropDownList1.Attributes.Add("onchange","alert('test');");
} --------------------编程问答-------------------- 使用 AJAX,DropDownList 刷新 GridView 进行数据绑定的简单实现
http://dotnet.aspx.cc/article/d94323a7-e322-4ead-9f25-6e6629c8012e/read.aspx --------------------编程问答-------------------- 写dropdownlist事件就可以了。 孟兄来了。 --------------------编程问答-------------------- 可不可以DropDownList调用JS事件呢?
补充:.NET技术 , C#