Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Databinding to Listbox


Message #1 by Navid Nobakht <navidnobakht@y...> on Tue, 31 Oct 2000 14:42:18 -0800 (PST)
Does anyone have some sample code for binding a

Dataview to a listbox in C#?



Message #2 by "Fredrik Normen" <fredrik.normen@e...> on Wed, 1 Nov 2000 08:44:11 -0000
<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SQL" %>



<html>



<script language="C#" runat="server">



    void Page_Load(Object sender, EventArgs e) {

    

    SQLConnection myConnection = new

SQLConnection("server=localhost;uid=sa;pwd=;database=northwind");

        SQLDataSetCommand myCommand = new SQLDataSetCommand("select * from

customer", myConnection);



        DataSet ds = new DataSet();

        myCommand.FillDataSet(ds, "Customer");



        ListBox1.DataSource = ds.Tables["Customer"].DefaultView;

        ListBox1.DataBind();

    }



</script>



<body>



    <asp:ListBox id="ListBox1" runat="Server" DataTextField="CustomerID"

DataValueField="ComanpyName"/>



</body>

</html>







/Fredrik Normén


  Return to Index