尝试从单选按钮列表中获取SelectedValue时的错误ASP.NET Web表单/ C#

时间:2015-07-23 16:37:53

标签: c# asp.net radio-button selectedvalue

我试图从ASP单选按钮列表中获取值并将它们存储到变量中。我试图使用SelectedValue。

我的C#代码显示此错误: 错误4'字符串'不包含' SelectedValue'的定义没有扩展方法' SelectedValue'接受类型' string'的第一个参数。可以找到(你是否错过了使用指令或汇编参考?)我是ASP的新手,所以很有可能它很简单。在此先感谢您的帮助!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace frmArtUpl
{
public partial class uploader : System.Web.UI.Page
{
    protected void ProcessArticulate_ServerClick(object sender, EventArgs e)
    {
        string existingArticulateAddress = "";
        string newOrExisting = "";
        string publishLocation = "";
        string publicOrSecured = "";

        existingArticulateAddress = Request.Form["existingArticulateAddress"];
        newOrExisting = newOrExisting.SelectedItem.Value;
        publishLocation = Request.Form["publishLocation"];
        publicOrSecured = publicOrSecured.SelectedValue;
    }

    protected void Page_Load(object sender, EventArgs e)
    {            

    }
}

}

以下是ASP:                           

            <div class="row">
                <asp:Label ID="Label1" runat="server" Text="Label">New or Existing Articulate?</asp:Label>
                <asp:RadioButtonList ID="newOrExisting" runat="server">
                    <asp:ListItem Text="New" Value="true" />
                    <asp:ListItem Text="Existing" Value="false" />
                </asp:RadioButtonList>
            </div>
            <br />
            <div class="row hiddenOnLoad">
                <asp:Label ID="Label2" runat="server" Text="Label">Enter Existing Articulate Address:</asp:Label>
                <input type="text" id="existingArticulateAddress" name="existingArticulateAddress" />
            </div>
            <br />
            <div class="row">
                <asp:Label ID="Label3" runat="server" Text="Label">Public or Secured?</asp:Label>
                <asp:RadioButtonList ID="publicOrSecured" name="publicOrSecured" runat="server">
                    <asp:ListItem Text="Public" Value="Public" />
                    <asp:ListItem Text="Secured" Value="Secured" />
                </asp:RadioButtonList>
            </div>
            <br />
            <div class="row hiddenOnLoad">
                <asp:Label ID="Label4" runat="server" Text="Label">Where to publish?</asp:Label>                    
                <asp:DropDownList ID="publishLocation" runat="server">
                    <asp:ListItem Text="Lending" Value="Lending" />
                    <asp:ListItem Text="Loanliner" Value="Loanliner" />
                    <asp:ListItem Text="TruStage" Value="TruStage" />
                </asp:DropDownList>
            </div>

        </div>
    </div>

3 个答案:

答案 0 :(得分:0)

当前代码中的publicOrSecured是一个字符串。您需要定位控件,而不是使用相同的名称命名变量。像这样:

string _publicOrSecured = ""; 
_publicOrSecured = publicOrSecured.SelectedValue;

答案 1 :(得分:0)

尝试使用关键字:

publicOrSecured = this.publicOrSecured.SelectedValue;

您遇到问题,因为您将您的字符串和RadioButtonList命名为同名。

答案 2 :(得分:0)

您的字符串和RadioButtonList具有相同的名称!

string publicOrSecured =“”;

asp:RadioButtonList ID =“publicOrSecured”

重命名一个!