Sunday, January 22, 2006

Adding a blank row to an ASP.NET drop down listbox

Have you ever wanted to add a blank row to your ASP.NET drop down list boxes like this when using it as a databound control?












This code uses a datarow and a dataview object to do just that.

Dim dr As DataRow = Session("ds").Tables("ClerkshipTypes").NewRow()
dr("ClerkshipTypeID") = 0
dr("Clerkship") = "----------------"
Session("ds").Tables("ClerkshipTypes").Rows.Add(dr)
Dim dv As DataView
dv = New DataView(Session("ds").Tables("ClerkshipTypes"))
dv.Sort = "ClerkshipTypeID"


This sets the list box control to have a ------------- as it's default row.

0 Comments:

Post a Comment

<< Home