如何检索所选select元素项的字符串值?

时间:2017-04-07 19:01:38

标签: vb.net html-select

之前的问题here是相关的。

我发现我真正需要知道的是更具体的内容,即如何检索所选select元素项的字符串值?

这就是我用来获取价值的东西:

Subcategory = Request.Form.Item("selectSubcategory").ToString()

...但无论选择哪个项目,它总是将“0”分配给子类别。

以下是代码中出现的“子类别”:

宣称:

Dim Subcategory As String

已分配(如上所示):

Subcategory = Request.Form.Item("selectSubcategory").ToString()

数据库写:

query2 &= "SET Subcategory = @SubCat "
. . .
.Parameters.Add("@Subcat", SqlDbType.NVarChar).Value = Subcategory

选择元素代码:

<select name="selectSubcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
    <% If Not IsNewBusiness Then%>
        <option <% If Subcategory = "0" Then Response.Write(" selected")%> value="0">Existing
        <option <% If Subcategory = "1" Then Response.Write(" selected")%> value="1">Organic Growth
    <% Else%>
        <option <% If Subcategory = "0" Then Response.Write(" selected")%> value="0">New
        <option <% If Subcategory = "1" Then Response.Write(" selected")%> value="1">Assumed
    <% End If%>
</select>

为什么“0”总是分配给Subcategory?如何指定所选项目的文本值?

更新

根据我读过的其他内容,我想也许我需要用“runat =”server“”jazz来装饰select元素。但是当我这样做时,就像这样:

<select name="selectSubcategory" runat="server" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">

我明白了:

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Server tags cannot contain <% ... %> constructs.

Source Error: 

Line 767:                                        </td>
Line 768:                                        <td nowrap align="left" valign="top">
Line 769:                                            <select name="selectSubcategory" runat="server" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
Line 770:                                            <%--<asp:dropdownlist name="selectSubcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">--%>
Line 771:                                                <% If Not IsNewBusiness Then%>

Source File: /EMS/pages/custmaint_entry.aspx    Line: 769

用希宾奖获奖的英雄希宾来解释,

更新2

又发生了一次;没有改变代码(或者更确切地说,在阳光下尝试所有东西,然后恢复到最初尝试的东西,之前没有工作),现在它可以工作。 Las Campanas del Infierno!

我还是回来了:

Subcategory = Request.Form.Item("selectSubcategory").ToString()

......而且这个:

<select name="selectSubcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">

......现在正在工作,而事实并非如此。

我不能告诉你我是多么高兴离开编程;我认为我不能超过这一周。烧坏?我被烧焦的烟熏焦了。

0 个答案:

没有答案