微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何让DropDownList 绑定null空值

静态声明:

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"

 

                    DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("ParentID") %>'

 

                    Style="position: relative" AppendDataBoundItems="True">

 

                   <asp:ListItem Value="">(无 或 空 或 all)</asp:ListItem><!--需要增加内容-->

 

 </asp:DropDownList>

 

动态添加

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"

 

                    DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("ParentID") %>'

 

                    Style="position: relative" AppendDataBoundItems="True">

 

 

 </asp:DropDownList>

以下为包含在GridView中的DropDownList添加一个空值项:

Protected Sub GV_Match_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV_Match.RowDataBound
        If (e.Row.RowType = DataControlRowType.Header Or e.Row.RowType = DataControlRowType.DaTarow) Then
                 Dim ddl As DropDownList = New DropDownList()
                ddl = e.Row.FindControl("DropDownList1")
                If Not ddl Is nothing Then
                    ddl.Items.Insert(0,new ListItem("NULL",String.Empty))

                End If
         End If
 End Sub

 

注意: 首选静态声明,因为动态绑定在显示空值的时候可能会出现问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐