DropDownList是放在母板页里。代码:
div class="search_middle">&nbsp;<asp:TextBox ID="word" runat="server"></asp:TextBox>&nbsp;分类:<asp:DropDownList ID="DropDownList1"
                       runat="server">
                   </asp:DropDownList>
                 
                   地区:<asp:DropDownList ID="DropDownList2"
                       runat="server">
                   </asp:DropDownList>
                    &nbsp;<asp:Button ID="search" runat="server" PostBackUrl="search.aspx" OnClientClick="if(subbit()==false){ return false;}" Text="搜索" />
                           </div>
母板页绑定代码:
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                conn reader = new conn();
                reader.OpenDB();
                String sql = "Select * from class";
                DataSet ds4 = reader.DataSets2(sql);
                this.DropDownList1.DataSource = ds4.Tables[0];
                this.DropDownList1.DataTextField = "names";
                this.DropDownList1.DataValueField = "id";
                this.DropDownList1.DataBind();
                this.DropDownList1.Items.Insert(0, new ListItem("全部", "0"));                sql = "Select * from area";
                DataSet ds5 = reader.DataSets2(sql);
                this.DropDownList2.DataSource = ds5.Tables[0];
                this.DropDownList2.DataTextField = "names";
                this.DropDownList2.DataValueField = "id";
                this.DropDownList2.DataBind();
                this.DropDownList2.Items.Insert(0, new ListItem("全部", "0"));                //关闭数据库
                reader.CloseDB();
            }
        }出来的html原代码:
<div class="search_middle">&nbsp;<input name="ctl00$ContentPlaceHolder1$word" type="text" id="ctl00_ContentPlaceHolder1_word" />&nbsp;分类:<select name="ctl00$ContentPlaceHolder1$DropDownList1" id="ctl00_ContentPlaceHolder1_DropDownList1">
<option value="0">全部</option>
<option value="1">求租</option>
<option value="2">招租</option>
<option value="3">求购</option>
<option value="4">出售</option>
<option value="5">收售</option>
<option value="6">转让</option>
<option value="7">交换</option>
<option value="8">求职</option>
<option value="9">招聘</option>
<option value="10">招生</option>
<option value="11">家教</option>
<option value="12">家政</option>
<option value="13">运输</option>
<option value="14">维修</option>
<option value="15">装修</option>
<option value="16">礼仪</option>
<option value="17">征婚</option>
<option value="18">交友</option>
<option value="19">旅游</option>
<option value="20">招商</option>
<option value="21">代理</option>
<option value="22">合作</option>
<option value="23">商机</option>
<option value="24">求助</option>
<option value="25">启示</option>
<option value="26">其他</option>
<option value="27">售房</option>
<option value="28">保姆</option>
<option value="29">宠物</option>
<option value="30">二手</option>
 
</select>
                 
                   地区:<select name="ctl00$ContentPlaceHolder1$DropDownList2" id="ctl00_ContentPlaceHolder1_DropDownList2">
<option value="0">全部</option>
<option value="1">武侯区</option>
<option value="2">金牛区</option>
<option value="3">青羊区</option>
<option value="4">锦江区</option>
<option value="5">成华区</option>
<option value="8">温江区</option>
<option value="9">高新东区</option>
<option value="10">高新西区</option>
<option value="11">成都周边</option>
 
</select>
                    &nbsp;<input type="submit" name="ctl00$ContentPlaceHolder1$search" value="搜索" onclick="if(subbit()==false){ return false;};WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentPlaceHolder1$search&quot;, &quot;&quot;, false, &quot;&quot;, &quot;search.aspx&quot;, false, false))" id="ctl00_ContentPlaceHolder1_search" />
                           </div>接收页面代码:
 protected void Page_Load(object sender, EventArgs e)
        {
            if (PreviousPage != null)
            {
                TextBox word = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("word");
                DropDownList classes = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList1");
                DropDownList area = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList2");
                
                String keyword = word.Text;
                String clas = classes.Text;
                String are = area.Text;


无论怎么选,得到的值都是第一个选项的值,也就是0,百度了很久也没找到解决办法,求大侠指点下。

解决方案 »

  1.   


    protected void Page_Load(object sender, EventArgs e)
            {
               if(!IsPostBack)
    {
                if (PreviousPage != null)
                {
                    TextBox word = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("word");
                    DropDownList classes = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList1");
                    DropDownList area = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList2");
                    
                    String keyword = word.Text;
                    String clas = classes.Text;
                    String are = area.Text;

    }
      

  2.   

     protected void Page_Load(object sender, EventArgs e)
            {
                if (PreviousPage != null)
                {
                    TextBox word = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("word");
                    DropDownList classes = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList1");
                    DropDownList area = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList2");
                    
                    String keyword = word.Text;
                    String clas = classes.Text;
                    String are = area.Text;

    }改成 protected void Page_Load(object sender, EventArgs e)
            {
     if (!IsPostBack)
                {            if (PreviousPage != null)
                {
                    TextBox word = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("word");
                    DropDownList classes = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList1");
                    DropDownList area = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList2");
                    
                    String keyword = word.Text;
                    String clas = classes.Text;
                    String are = area.Text;
    }
    }
    }
      

  3.   

    一楼好快 呵呵 加个if (!IsPostBack)试下。
      

  4.   

     DropDownList classes = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList1");
    能查询控件
    selectedvalue
    或在母板页中定义属性PreviousPage.mater通过实行取值看看
      

  5.   

    谢谢,按照1楼的做了,能获取到word,但是2个DropDownList值都为空。
      

  6.   

    按照4楼的:
    DropDownList classes = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DropDownList1");
     String clas = classes.SelectedValue;得到的值任然为空。
      

  7.   

    数据绑上了,点的时候也能选择不同的选项,如果接受页不加(!IsPostBack)
    ,得到的2个值都是0,无论选哪个都是0,加上(!IsPostBack),无论选哪个,值都是空
    classes.SelectedValue;
    classes.Text;
    2个都是空。
    而word却能得到值,那个是输入框的。
      

  8.   

    不加(!IsPostBack)
    textbox 是否获取值
    使用属性看看
      

  9.   

    母板页和接收页都不加(!IsPostBack),测试结果:页面显示正常,数据选项都有,但是无论选哪个,获取到的选项值都是0,也就是第一个选项的值。
    classes.SelectedValue;
    classes.Text;
    2个值都是0,不是空。
      

  10.   

    有人说问题出在是在master里面绑定的值,
      走应用母版页的页面时master.cs绑定会走两次,值就丢啦
    就是说我的发送页和接受页都用了同一个母板页,接收页运行的时候,导致控件重新绑定了,所以值丢了。如果是这样的话,这个问题怎么解决呢?
      

  11.   

    对了,你的那个DropDownList控件的AutoPostBack属性设置成True了没有?
      

  12.   

    这样设置下其他的2个DropDownList控件应该也是可以取到值的,你试下