| |

VerySource

 Forgot password?
 Register
Search
View: 2026|Reply: 14

C # how to bind the drop-down box

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-6 17:20:01
| Show all posts |Read mode
C # how to bind the drop-down box
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-6 20:03:01
| Show all posts
dropprovince.DataSource = myajax.Getprovince ();
        dropprovince.DataTextField = "province_name";
        dropprovince.DataValueField = "province_id";
        dropprovince.DataBind ();
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-6 20:45:01
| Show all posts
Using the DropDownList control
DropDownList.DataSource = DataSet.Tables ["YourTaleName"];
        DropDownList.DataTextField = "name";
        DropDownList.DataValueField = "id";
        DropDownList.DataBind ();
Same as ls principle
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-1-7 00:30:01
| Show all posts
All said upstairs!
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-1-7 19:36:01
| Show all posts
Combobox does not count drop-down box, this is in WinForm ...

for example:

SqlConnection con = new SqlConnection ("server = .; database = student; uid = sa; pwd = 0421");
SqlDataAdapter sda = new SqlDataAdapter ("select * from studentDetails", con);
DataSet ds = new DataSet ();
sda.Fill (ds, "student");
this.ComboBox1.DataSource = ds.Tables ["student"];
this.ComboBox1.DisplayMember = "sname";


// If it is a WebForm, you can use the DropDownList said by some upstairs ..
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-10 20:27:01
| Show all posts
Although binding can improve development efficiency, but it is not scalable, it is best to write it yourself, and you don't know what happened inside the binding
Reply

Use magic Report

0

Threads

13

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-10 21:54:01
| Show all posts
Agree upstairs
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-11 14:54:01
| Show all posts
this.combobox.datasource = dataset1.tables ["tablename"];
this.combobox.displaymember = dataset1.tables ["tablename"]. columns ["name"]. tostring ();
this.combobox.tag = dataset1.tables ["tablename"]. columns ["flag"];
Data binding is similar
Reply

Use magic Report

0

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Hong Kong

Post time: 2020-1-11 17:45:01
| Show all posts
Haha
Reply

Use magic Report

0

Threads

10

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-19 16:54:01
| Show all posts
ComboBox1.DataSource = myDataSet; // Dataset
ComboBox1.DisplayMember = "person.userId"; // Table name plus field name
ComboBox1.ValueMember = "person.username";

this.ComboBox1.DataSource = myDataTable; // Data Table
this.ComboBox1.DisplayMember = "Name"; // Field name
this.ComboBox1.ValueMember = "userId"; // field name
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list