0

谢谢 SOF,我在这里提出另一个 asp.net 问题。

在我的 asp 下拉列表控件中,我使用 appenddatabounditems 功能绑定到一个 asp listitem

<asp:DropDownList ID="CMListDD" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="CMListDD_ODS" >
           <asp:ListItem value="" Text="Select a CM"/>
        </asp:DropDownList> 

我搜索了 MSDN,并认为 .net 应该将其呈现为 html

<option value="">Select a Product</option>

在我后面的代码中,我有一个对象数据源绑定到我的 gridview 以根据我的下拉列表中的选定值返回一个表。我使用 string.IsNullOrEmpty 来捕捉这个空值,但不知何故,该函数没有捕捉到这个空值。

 public DataTable GetPRList(string CM)
            {

                if (string.IsNullOrEmpty(CM))
                {
                   return null;
                }
                else
    {
    // do sth
    }
}

if 子句不捕获空字符串,而是去 else{}。有人知道为什么吗?

谢谢

4

1 回答 1

0

如果您的下拉列表看起来像这样,它应该可以工作

<asp:DropDownList id="DropDownList1" runat="server"
    Appenddatabounditems="true">

   <asp:ListItem Value="" Text="-- Select a Product --"></asp:ListItem>

</asp:DropDownList>

注意:我设置了Value=""

于 2013-01-02T18:41:38.193 回答