| |

VerySource

 Forgot password?
 Register
Search
View: 580|Reply: 3

Ask a simple question, please help me

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-31 08:40:01
| Show all posts |Read mode
The table structure is as follows
a b
1 2
3 4
5 6
How to bind DropDownList to connect the contents of the two ab fields and display them in the drop-down box?
string comstr1 = "select DISTINCT companyid from templateinfo";
con.Open ();
SqlCommand cmd1 = new SqlCommand (comstr1, con);
SqlDataReader dr1 = cmd1.ExecuteReader ();
this.DropDownList2.DataSource = dr1;
this.DropDownList2.DataTextField = "a" + "b";
this.DropDownList2.DataBind ();
con.Close ();
The effect should be to pull down 12, 23, 34. My code can't be written like that. Everyone help me change it ~~ Thank you ~~
Reply

Use magic Report

0

Threads

29

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-3-8 23:45:01
| Show all posts
select DISTINCT companyid, a + b from
Reply

Use magic Report

0

Threads

14

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-9 08:45:02
| Show all posts
Method 1: Merge in SQL statements
select c = convert (nvarchar, a) + convert (nvarchar, b) from templateinfo

Method 2: Get the DataTable first, then process the DataTable and add a field to merge the two columns
Reply

Use magic Report

1

Threads

60

Posts

37.00

Credits

Newbie

Rank: 1

Credits
37.00

 China

Post time: 2020-3-9 22:15:01
| Show all posts
foreach (DataRow dRow in DSet.Tables [0] .Rows)
        {
            ListItem LItem = new ListItem (dRow [DataTextValue] .ToString () + "" + dRow [DataTextFiled] .ToString (), dRow [DataTextValue] .ToString ());
            drpList.Items.Add (LItem);
        }
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