首页 新闻 会员 周边

DropDownList绑定数据,二级联动为什点DropDownList1会出错?

0
[已解决问题] 解决于 2013-03-05 11:28

前台代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../js/jquery-1.4.1.min.js" type="text/javascript"></script>
    <link href="../../Content/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel runat="server" ID="UpdatePannel1">
        <ContentTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"   OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList2" runat="server">
            </asp:DropDownList>
          <%--  <asp:DropDownList ID="DropDownList3" runat="server">
            </asp:DropDownList>--%>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
            <%--<asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged" />--%>
        </Triggers>
    </asp:UpdatePanel>
    </form>
</body>
</html>

下边这是后台:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 using System.Data.OleDb;
 8 using System.Data;
 9 using System.Configuration;
10 
11 namespace TaovoAll.JiLian
12 {
13     public partial class WebForm1 : System.Web.UI.Page
14     {
15 
16       
17         private BLL.UserServer userServer = new BLL.UserServer();                                                                 
18         protected void Page_Load(object sender, EventArgs e)
19         {
20 
21 
22             if (!IsPostBack)
23             {
24 
25                 bindDropDownList1();
26 
27             }
28 
29 
30         }
31 
32         protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
33         {
34                 IList<Models.Userinfo> user = userServer.GetAllPlayType();
35                 DropDownList2.DataSource = user;
36                 DropDownList2.DataBind();
37                 DropDownList2.DataTextField = "plty_playtypename";
38                 DropDownList1.DataValueField = "plty_lotteryid";
39                 DropDownList2.Items.Insert(0, new ListItem("--请选择--"));
40              
41  
42         }
43 
44      
45 
46         public void bindDropDownList1()
47         {
48            
49             IList<Models.Userinfo> user = userServer.GetAllLottery();
50             DropDownList1.DataSource = user;
51             DropDownList1.DataTextField = "loty_lotteryname";
52             DropDownList1.DataValueField = "loty_id";
53             DropDownList1.DataBind();
54             DropDownList1.Items.Insert(0, new ListItem("--请选择--"));
55           
56         }
57 
58     }
59 }

这个是数据访问层代码

View Code
        //获得彩票类型
        public IList<Models.Userinfo> GetAllLottery()
        {
            string sql = "select loty_id,loty_lotteryname from Tab_LotteryType";
            List<Models.Userinfo> list = new List<Models.Userinfo>();

            using (SqlDataReader reader = DBUtility.SQLHelper.ExecuteQuery(System.Data.CommandType.Text, sql, null))
            {

                while (reader.Read())
                {

                    Models.Userinfo users = new Models.Userinfo(
                    reader.GetByte(0),reader.GetString(1)
                     );
                    list.Add(users);
                }
                return list;

            }
        }

        //获得玩法
        public IList<Models.Userinfo> GetAllPlayType()
        {

            string sql = "select plty_playtypeid,plty_playtypename,plty_lotteryid from Tab_PlayType";
            List<Models.Userinfo> list = new List<Models.Userinfo>();
            using (SqlDataReader reader = DBUtility.SQLHelper.ExecuteQuery(System.Data.CommandType.Text, sql, null))
            {

                while (reader.Read())
                {

                    Models.Userinfo users = new Models.Userinfo(
                   reader.GetInt32(0),
                    reader.GetString(2) , reader.GetInt32(1)
                    );
                    list.Add(users);
                }
                return list;

            }
        }


为什么点击DropDownList1下拉数据回报错 ,那位高手指点下谢谢

问题补充:

那个是错误页面

yujinchao的主页 yujinchao | 菜鸟二级 | 园豆:248
提问于:2013-02-26 15:47
< >
分享
最佳答案
0
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
33         {
34                 IList<Models.Userinfo> user = userServer.GetAllPlayType();
35                 DropDownList2.DataSource = user;
36                 DropDownList2.DataBind();
37                 DropDownList2.DataTextField = "plty_playtypename";
38                 DropDownList1.DataValueField = "plty_lotteryid";
39                 DropDownList2.Items.Insert(0, new ListItem("--请选择--"));
42         }
你看一下标红的地方。这里估计有错误。你先修改了再看看


奖励园豆:5
yj.l | 菜鸟二级 |园豆:207 | 2013-02-26 16:16

已经实现了,为 什么不联动啊

yujinchao | 园豆:248 (菜鸟二级) | 2013-02-26 17:28

@yujinchao: 参看 http://q.cnblogs.com/q/15813

你绑定数据源是,没有作关联查询。肯定不联动

yj.l | 园豆:207 (菜鸟二级) | 2013-02-28 14:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册