Click here to Skip to main content
14,838,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm populating a dropdown list from database table. I' m taking as a value the ID of that table and as a text the combination of two columns, the code is as following:
SQL
SELECT PERSON.ID_Person, (PERSON.FName+ ' ' + PERSON.LName)as FirstLastName FROM PERSON


Ok this works good.
The problem is to the code when I select the row to the SelectedIndexChanged.
All other columns work fine except the column that I concatenated the fname and lname.
The Grid View gvPerson is reading those columns in the same manner as the DropDownList,it concatenates those two columns as well.
The code in C# ASP.NET when selecting a row is as following
C#
ddListPerson.SelectedValue= gvPerson.SelectedRow.Cells[6].Text;

How to fix this to show the value on ddl when selecting a row.
Thank you in advance for your reply.
Cheers.
Posted
Updated 14-Nov-15 22:52pm
v2

Use below code:
C#
ddListPerson.ClearSelection();

// If it is value of the dropdown then use FindByValue()
ddListPerson.Items.FindByValue(gvPerson.SelectedRow.Cells[6].Text).Selected = true;

// OR If it is display text of the dropdown then use FindByText()
ddListPerson.Items.FindByText(gvPerson.SelectedRow.Cells[6].Text).Selected = true;

Make sure that name(concatenated) is loaded properly before use FindByValue() method.
   
v2
Thank you, I never used the method to concatenate two columns in one, so i had the problem to show that in dropdown list. In case that someone else has the same problem I'll give a solution that worked for me:
SQL
ddListPerson.SelectedItem.Text  = gvPerson.SelectedRow.Cells[6].Text;


Once again thank you all.
Cheers.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900