Results 1 to 2 of 2

Thread: Custom binding in code...

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim x As New XmlTextReader(New IO.FileStream(Server.MapPath("clients.xml"), IO.FileMode.Open, IO.FileAccess.Read))
    3.         Dim d As New DataSet
    4.  
    5.         d.ReadXml(x)
    6.         x.Close()
    7.  
    8.  
    9.         Try
    10.             With DropDownList1
    11.                 .DataTextField = "name"
    12.                 .DataValueField = "id"
    13.                 .DataSource = d.Tables(0)
    14.                 .DataBind()
    15.             End With
    16.         Catch ex As Exception
    17.             Response.Write(ex.Message)
    18.         End Try
    19.  
    20.     End Sub
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    That looks good to me.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width