blah blah blah is here! blah blah » Close

up0down
link

Hi

I'm doing a web application in VS2008 (C#), and I got stucked. I have a webform with 1 dropdownlist for collecting the first names of the employees, and then some textboxes where the user enter his data into. The user will select his name from the droplist and then enter some data in the textboxes which will be saved into a sql database. My issue is, if there are two people with the same first name it will be hard to know which first name to pick, I would like to either have both first name and lastname in the droplist or have a label that displays the lastname next to the droplist. When the user select a first name the label will automaticly change and display the lastname. I do not manage to do so.
Can you please help me? Thank you.

last answered one year ago

2 answers

up0down
link

to do this label thing, you should code this in javascript rather than asp.net unless you are using ajax. to do this in both cases store the value of the item as the last name and the text as the first name. then if you are using ajax, change the label text to the value of the selected item.

up0down
link

Hi

Thanks for your reply, I found another way to solve my problem. Now I have both firstname and lastname in the same dropdownlist and that will do for me.
I like to share my code, if someone else run it to this issue...

myCommand = new SqlCommand("SELECT * FROM Employee", myConnection);
myCommand.CommandType = CommandType.Text;
myCommand.Connection = myConnection;

SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet, "Employee");

DataColumn newColumn = new DataColumn();
newColumn.ColumnName = "fullname";
newColumn.DataType = System.Type.GetType("System.String");
newColumn.Expression = "Firstname+' '+Lastname";
myDataSet.Tables[0].Columns.Add(newColumn);

DropDownList1.DataTextField = "FullName";
DropDownList1.DataValueField = "NameId";
DropDownList1.DataSource = myDataSet.Tables[0].DefaultView;

DropDownList1.DataBind();

muster
1556

good to hear that

Feedback