using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using webwinscom.DAL.proClassIdTableAdapters;namespace webwinscom.admin
{
public partial class addpro : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string x = DropDownList1.SelectedValue;
string xx = "SELECT [Pro_name], [pro_ClassId] FROM [Pro_NameID] where pro_ClassId=" + x;
SqlDataSource2.SelectCommand = xx;
}
}
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using webwinscom.DAL.proClassIdTableAdapters;namespace webwinscom.admin
{
public partial class addpro : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string x = DropDownList1.SelectedValue;
string xx = "SELECT [Pro_name], [pro_ClassId] FROM [Pro_NameID] where pro_ClassId=" + x;
SqlDataSource2.SelectCommand = xx;
}
}
}
解决方案 »
- GridView 绑定Access 数据源出现 “至少一个参数没有被指定值。”错误
- 在网站上做了一个检测到是IE6的话自动跳转到升级IE界面
- 对Gridview了解的请 进来下~!!!!!!!!!!
- 水晶报表四舍五入问题
- 如何用程序取消某个参数?
- 求救???怎样调出一个对话框
- Response.Redirect可以用;Page.RegisterStartupScript为什么就有问题》?
- datagrid绑定dataset的多个datatable---在线等
- 用treeview的问题??
- 请问我想在输入名称和密码错误后弹出对话框,提示出错。怎么showmessagbox呀?谢谢!
- 控件怎么无法绑定事件了
- 怎样把后台变量呈现在ASPX界面中,而不使用LABLE
<td class="style3" >
<asp:Label ID="Label1" runat="server" Text="所属父类:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="protype" DataValueField="ProClass" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:T_winscomConnectionString %>"
SelectCommand="SELECT DISTINCT [protype], [ProClass] FROM [Pro_TypeID]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="style3" >
<asp:Label ID="Label2" runat="server" Text="类别名称:"></asp:Label> <asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Pro_name"
DataValueField="pro_ClassId" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:T_winscomConnectionString %>"
SelectCommand="SELECT [Pro_name], [pro_ClassId] FROM [Pro_NameID]">
</asp:SqlDataSource>
</td>
</tr>
DropDownList2.Items.FindByValue("").Selected = true;//根据value
或设置DropDownList1为参数,根据参数联动
还有AJAX
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>DropDownList1的数据你是从数据库里读取的,DropDownList2的数据先不用绑定后台
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string value = this.DropDownList1.SelectedItem.Value.ToString();
this.DropDownList2.Items.Clear();
this.DropDownList2.Items.Add(new ListItem(value, value));//如果你是根据选择的数据再查询出一个集合的话,上面的就不用换下面的
this.DropDownList2.DataSource = dt;
this.DropDownList2.DataTextField = "显示的字段";
this.DropDownList2.DataValueField = "一般是ID";
this.DropDownList2.DataBind();
}
DropDownList2取消了autopostback,
现在DropDownList2能根据DropDownList1的值来读取数据,
但是无论怎么选Response.Write(DropDownList2.SelectedItem.Text) 显示出来的值总是DropDownList2里面的第一项
http://www.cnblogs.com/zhangyu028/articles/310568.html
改成SelectCommand="SELECT [Pro_name] FROM [Pro_NameID]">
就可以了。
但还是不懂为什么?