获取DropDownList值会产生奇怪的行为

时间:2010-01-03 08:56:20

标签: asp.net drop-down-menu

我在页面上有一个DropDownList

<select name="Pages1$RadPanelBar1$i0$i0$ddlParentPage" id="Pages1_RadPanelBar1_i0_i0_ddlParentPage" tabindex="2">
    <option value="0">[main menu]</option>
    <option value="1">Home</option>
    <option value="3">Getting Connected</option>
    <option value="5">Communications</option>
    <option value="35">Sitemap</option>
    <option value="46">SlideShow</option>
 </select>

我遇到的问题是以下代码将 ParentID 设置为0(对我而言,显然不应该发生)

    'get parent page
    Dim ParentID As Integer = Nothing
    Dim DDLValue As Integer = Integer.Parse(ddlParentPage.SelectedItem.Value)
    If DDLValue > 0 Then
        ParentID = ddlParentPage.SelectedItem.Value
    End If

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

所以我使用SQL代替Code来解决这个问题。

我在代码中完全删除了IF语句,只是将ddl.selecteditem.value提交到数据库存储过程中。

从那里我做了一个SQL IF语句

    IF @ParentID = 0
Begin
    Insert Into icms_Pages
        (
            ParentID,

        )
    Values
        (
            Null,

        )
END
ELSE
    Insert Into icms_Pages
        (
            ParentID,

        )
    Values
        (
            @ParentID,