Saturday, March 24, 2012

Populate DropDown with dataview

I have a bunch of dropdown on my form and I am trying to optimize the populating process. I am filling a dataview with a store proc and pass the dataview to each dropdown's datasource with a filter and sort expression. Until then every thing is fine however I need to add a black row at the top of each drop down and I dont know how to add it to my dataview or directly to dropdown. Any help would be great.

Here is what I got up to now


fctFillDropDownList(ddSource, 30, strSortAsc, dvTemp)
...

'*************************************************************************
'*************************************************************************
Private Sub fctFillDropDownList(ByRef objControl As System.Web.UI.WebControls.DropDownList, _
ByVal iParentID As Int16, ByVal strSort As String, ByRef dvTemp As DataView)
'*************************************************************************
dvTemp.RowFilter = "parentId=" & iParentID
dvTemp.Sort = strSort
objControl.DataSource = dvTemp
objControl.DataTextField = "Texte"
objControl.DataValueField = "Texte"
End Sub

After you call DataBind on the dropdownlist, you can do this (C# syntax):

MyDropDownList.Items.Insert(0, new ListItem("", ""));

That will add a blank row at the beginning of the dropdownlist.

HTH
Thanks that worked

0 comments:

Post a Comment