Custom binding in code...
I have a datatable with two columns : name , id
I have a drop down list, and I would like the text for each item to be [name] - [id].
The only way I can think of doing that is through custom binding, but how would you create a bind expression at run time?
Here is what I have now...
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As New XmlTextReader(New IO.FileStream(Server.MapPath("clients.xml"), IO.FileMode.Open, IO.FileAccess.Read))
Dim d As New DataSet
d.ReadXml(x)
x.Close()
Try
With DropDownList1
.DataTextField = "name"
.DataValueField = "id"
.DataSource = d.Tables(0)
.DataBind()
End With
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub