前台
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" Height="17px" Width="125px">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
        </asp:DropDownList>
        
         <asp:DropDownList ID="DropDownList2" runat="server" 
                DataSourceID="SqlDataSource1" DataTextField="car_pic_param_name" 
                DataValueField="car_pic_param_id" Height="25px" Width="86px">
               
            </asp:DropDownList>
            <br />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:Car_SaleConnectionString %>" 
                SelectCommand="SELECT * FROM [Car_Pic_Param]"></asp:SqlDataSource>
        
            <br />
    </div>
    </form>
</body>
</html>
后台 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string cc = this.DropDownList1.SelectedValue;
            string dd = this.DropDownList2.SelectedValue;
        }
    }
我dropdownlist1直接写,可以获取到,
dropdownlist2从数据库读取,获取不到
我怎么样才能在page_load首次加载的时候,获取到从数据中读取的dropdownlist2呢,求解啊!

解决方案 »

  1.   

    把绑定事件自己写在Load事件里啊
      

  2.   

    - - !用反了 
    protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                string cc = this.DropDownList1.SelectedValue;
                string dd = this.DropDownList2.SelectedValue;
            }
        }
      

  3.   

    光指定了数据源没有执行绑定方法,在Page_Load方法里加一句:
    DropDownList2.DataBind();
      

  4.   

    编辑某个案例,要在DropDownList显当前案例的类型,<tr>
        <td width="120" align="right">案例类型</td>
        <td>
            <asp:DropDownList ID="ddlTypes" runat="server"></asp:DropDownList>
            <asp:Literal ID="lal" runat="server"></asp:Literal></td>
        <td width="464">&nbsp;</td>
      </tr>
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    ShowAllTypes();//先绑定
                    int i = 0;
                    if (int.TryParse(Request.QueryString["pid"], out i))
                    {
                        if (i > 0)
                        {
                            ShowProInfoByEID(i);
                        }
                    } 
                }
            }
    protected void ShowAllTypes()
            {
                this.ddlTypes.DataSource = DAL.AccessService.TypesService.GetAllTypes();//数据库读取
                ddlTypes.DataTextField = "TP_Name";
                ddlTypes.DataValueField = "TPID";
                this.ddlTypes.DataBind();
            } /// <summary>
            /// 载入图片:在编辑更新案例时执行该方法
            /// </summary>
            /// <param name="id"></param>
            protected void ShowProInfoByEID(int id)
            {
                Projcets pro = ProjectsService.GetProByPIDToProDetail(id);//通过ID读取一条数据并显示
                if (pro != null)
                {
                    //省略·····ddlTypes
                    ddlTypes.SelectedItem.Value = pro.P_Type.TPID.ToString();//显示当前案例的类型
                    ddlTypes.SelectedItem.Text = pro.P_Type.TP_Name;            }
            }
      

  5.   


    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string cc = this.DropDownList1.SelectedValue;
                DropDownList2.DataBind();
                string dd = this.DropDownList2.SelectedItem.Text.ToString();
            }
        }
      

  6.   

    你确定DropDownList2绑定到数据了吗