尝试从单选按钮列表获取SelectedValue时出现错误.. NET web表单/ c#



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

这个错误显示在我的c#代码中:错误4 'string'不包含'SelectedValue'的定义,并且没有扩展方法'SelectedValue'接受类型'string'的第一个参数可以找到(您是否缺少using指令或程序集引用?)我是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>

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

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

尝试使用这个关键字:

publicOrSecured = this.publicOrSecured.SelectedValue;

你有问题,因为你命名你的字符串和你的RadioButtonList具有相同的名称

你的字符串和RadioButtonList有相同的名字!

string publicOrSecured = ";

asp: RadioButtonList ID ="publicOrSecured"

重命名一个!

相关内容

最新更新