这是前台代码<table width="700"  ><tr>
    <td style="width:150px;" valign="top">
        <span>&nbsp;&nbsp;宿舍类型: </span>&nbsp;&nbsp;
    </td>
    <td valign="top"> 
        <asp:RadioButtonList ID="dorm" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem>标准四人间</asp:ListItem>
            <asp:ListItem>标准六人间</asp:ListItem>
            <asp:ListItem>普通六人间</asp:ListItem>
            <asp:ListItem>普通八人间</asp:ListItem>
        </asp:RadioButtonList>
        
        <hr  style="color:#dce9ef;border-width:thin;" width="450" align="left" /><br />
    </td>
    </tr>
    <tr><td style="width:150px;" valign="top">&nbsp;&nbsp;<span>性别:</span>&nbsp;&nbsp;</td>
    <td valign="top">
        <asp:RadioButtonList ID="sex" runat="server" RepeatDirection="Horizontal"  OnTextChanged="sex_TextChanged" AutoPostBack="True">
            <asp:ListItem>男</asp:ListItem>
            <asp:ListItem>女</asp:ListItem>
        </asp:RadioButtonList>
        
        <hr  style="color:#dce9ef;border-width:thin;" width="450" align="left"/><br />
    </td></tr>
    <tr><td style="height: 24px" >
        <asp:Label ID="lnum" runat="server" Width="150px"></asp:Label></td>
    <td style="height: 24px"><asp:Label ID="lnumtext" runat="server" Width="150px"></asp:Label></td>
    </tr>
    <tr><td colspan="2" align="center">
        <asp:Button ID="Button1" runat="server" Height="26px" OnClick="Button1_Click" Text="确认" /></td></tr>
        
    </table>
下面是后台代码:
protected void sex_TextChanged(object sender, EventArgs e)
    {
        this.lnum.Text="<span style=\"color:blue; font-siz:20px;\">&nbsp;楼号:</span>";
        String dorm = this.dorm.Text;
        String sex = this.sex.Text;
        DataAccess da = new DataAccess();
        SqlDataReader rdr = da.get("select lnum from apartmentSource where atype = '" + dorm + "' and asex ='" + sex + "'");
        String a = "<font style=\"color:black;\">";
        while (rdr.Read())
        {
            a = a + "<input type=\"radio\" name=\"fno\">"+rdr[0]+"&nbsp;&nbsp;";
        }
        this.lnumtext.Text = a;//*/
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String f = Request.Form[fno];
        Response.Redirect("dormsearch.aspx?fno=" + f);
    }
运行以后出现的错误:
当前上下文中不存在名称“fno”

解决方案 »

  1.   

    <table width="700"  > <tr>
        <td style="width:150px;" valign="top">
            <span>&nbsp;&nbsp;宿舍类型: </span>&nbsp;&nbsp;
        </td>
        <td valign="top">
            <asp:RadioButtonList ID="dorm" runat="server" RepeatDirection="Horizontal">
                <asp:ListItem>标准四人间 </asp:ListItem>
                <asp:ListItem>标准六人间 </asp:ListItem>
                <asp:ListItem>普通六人间 </asp:ListItem>
                <asp:ListItem>普通八人间 </asp:ListItem>
            </asp:RadioButtonList>
           
            <hr  style="color:#dce9ef;border-width:thin;" width="450" align="left" /> <br />
        </td>
        </tr>
        <tr> <td style="width:150px;" valign="top">&nbsp;&nbsp; <span>性别: </span>&nbsp;&nbsp; </td>
        <td valign="top">
            <asp:RadioButtonList ID="sex" runat="server" RepeatDirection="Horizontal"  OnTextChanged="sex_TextChanged" AutoPostBack="True">
                <asp:ListItem>男 </asp:ListItem>
                <asp:ListItem>女 </asp:ListItem>
            </asp:RadioButtonList>
           
            <hr  style="color:#dce9ef;border-width:thin;" width="450" align="left"/> <br />
        </td> </tr>
        <tr> <td style="height: 24px" >
            <asp:Label ID="lnum" runat="server" Width="150px"> </asp:Label> </td>
        <td style="height: 24px"> <asp:Label ID="lnumtext" runat="server" Width="150px"> </asp:Label> </td>
        </tr>
        <tr> <td colspan="2" align="center">
            <asp:Button ID="Button1" runat="server" Height="26px" OnClick="Button1_Click" Text="确认" /> </td> </tr>
           
        </table>
    下面是后台代码:
    protected void sex_TextChanged(object sender, EventArgs e)
        {
            this.lnum.Text=" <span style=\"color:blue; font-siz:20px;\">&nbsp;楼号: </span>";
            String dorm = this.dorm.Text;
            String sex = this.sex.Text;
            DataAccess da = new DataAccess();
            SqlDataReader rdr = da.get("select lnum from apartmentSource where atype = '" + dorm + "' and asex ='" + sex + "'");
            String a = " <font style=\"color:black;\">";
            while (rdr.Read())
            {
                a = a + " <input type=\"radio\" name=\"fno\">"+rdr[0]+"&nbsp;&nbsp;";
            }
            this.lnumtext.Text = a;//*/
           
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            String f = Request.Form[fno];
            Response.Redirect("dormsearch.aspx?fno=" + f);
        }
    运行以后出现的错误:
    当前上下文中不存在名称“fno”
      

  2.   

    这个变量是在前台的啊。获取radio里面的值的啊radio是在点击 男 或 女 以后出现的
      

  3.   

    这问题解决了!! 但是这样改以后 在dormsearch.aspx 页面为什么接受的是个空值。
      

  4.   

    正解 得加双引号
    问题2: 你首先在这边调试看下String f = Request.Form[fno];
            Response.Redirect("dormsearch.aspx?fno=" + f); 中f为空不?
    不为空 然后在 dormsearch.aspx页 Request.QueryString["fno"].Tostring();
      

  5.   

    Request.Form[fno]; Form["这里这能是控件的的name值(不是所有的控件都可以通过post来传递值的,想span就不能传递,input倒是可以的)"]
      

  6.   


    蒽 只能是表单中的元素 根据它的name值来获取