首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

DropDownList和ListView结合显示数据的有关问题

2012-03-21 
DropDownList和ListView结合显示数据的问题HTML codetrtd请选择主机厂:asp:DropDownList IDddlCust

DropDownList和ListView结合显示数据的问题

HTML code
<tr>                <td>                    请选择主机厂:<asp:DropDownList ID="ddlCustomer" runat="server" OnSelectedIndexChanged="ddlCustomer_changed">                    </asp:DropDownList>                    </td>            </tr>            <tr>                <td>                    <asp:ListView ID="ListView1" runat="server" DataKeyNames="productid">            <AlternatingItemTemplate>            ........................................

C# code
protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                BLL.Orders orders=new BLL.Orders();                ddlCustomer.DataSource = orders.getCustomersDataSet();                ddlCustomer.DataValueField = "customerid";                ddlCustomer.DataTextField = "name";                ddlCustomer.DataBind();                ListView1.DataSource = orders.getProductsDataSetByCustomerId(int.Parse(ddlCustomer.SelectedValue));                ListView1.DataBind();            }        }        protected void ddlCustomer_changed(object sender, EventArgs e)        {            BLL.Orders orders = new BLL.Orders();            ListView1.DataSource = orders.getProductsDataSetByCustomerId(int.Parse(ddlCustomer.SelectedValue));            ListView1.DataBind();        }

但测试是这样的 我在dropdownlist控件中选择了别的选项 而列表ListView并没有被更新,还是显示页面一打开的数据,难道是DropDownList控件的OnSelectedIndexChanged事件没有触发吗?但我的确更换其中的选项了啊

[解决办法]
<asp:DropDownList AutoPostBack="true"

才会执行 OnSelectedIndexChanged

热点排行