ListItem and DropDownList binding data

xiaoxiao2021-03-06  45

In the case of problems, control listItem and DropDownList bind database data after SELECTEDINDEX

The value is always -1, causing the index number that cannot be selected.

> Consider a solution:

First, use! Ispostback

Second, not directly bind, database data is connected to arraylist, then use controls

> Items.add method Add content

DIM myconn as sqlconnection = new sqlconnection ("Server = localhost;" & _

"Database = PUBS; UID = SA; PWD =")

DIM mycmd as sqlcommand = new sqlcommand ("SELECT AU_ID," & _

"au_lname from authors", myconn)

myconn.open ()

Dim MyReader as SqldataReader = mycmd.executeRead ()

'Set up the data binding.

AuthorList.DataSource = MyReader

AuthorList.DataTextField = "AU_LNAME"

AuthorList.DataValuefield = "au_id"

Authorlist.database ()

'Close the Connection.

myconn.close ()

MyReader.close ()

'Add the item at the first position.

AuthorList.Items.insert (0, "<- select ->")

转载请注明原文地址:https://www.9cbs.com/read-60623.html

New Post(0)