Binding Data to a dropdown [Resolved]

Posted by Vijayar under C# on 5/18/2011 | Points: 10 | Views : 3154 | Status : [Member] | Replies : 9
HI

.I Have one dropdown list and 2 tables by name country and state with the following fields
Country ------->Country id,Country Name
State-------------->stateid,country id,statename where country id foreign key in state table
Now i want to bind the data to one dropdownlist with country names in bold and states in normal first,after selecting state the combination of state and city what we selected should appear along with the other data( remaining Countries and states).And when i click on save button the id's of selected state and country should be saved into a table(second table)

Ex
Country1 India
State1 Ap
State2 Bihar
Country2 America
State1 Washington
state2 Mexico

------
If we select India as country and Ap as state in the dropdown should look like India-Ap . along with remaining countries and states Please help me

to solve this issue.it's very urgent

vijaya


Responses

Posted by: Ndebata on: 5/19/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Please take a look at the attached code.
In GetData ( Try to get the data from database and return a DataTable )
And On Button Click instead of writing in to response save it to db where you need :)
 Download source file

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/19/2011 [Member] Starter | Points: 25

Up
0
Down

Hi
i used this code to bind to a table

DataSet ds = new DataSet();
da.Fill(ds);

DataTable dt = new DataTable();
da.Fill(ds);
dt = ds.Tables[0];


DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "CountryName";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
return dt;


But i am the runtime error as Collection was modified; enumeration operation may not execute. at this statement


Collection was modified; enumeration operation may not execute.

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/19/2011 [Member] Starter | Points: 25

Up
0
Down

Hi
i used this code to bind to a table

DataSet ds = new DataSet();
da.Fill(ds);

DataTable dt = new DataTable();
da.Fill(ds);
dt = ds.Tables[0];


DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "CountryName";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
return dt;


But i am the runtime error as Collection was modified; enumeration operation may not execute. at this statement


Collection was modified; enumeration operation may not execute.

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 5/19/2011 [Member] Starter | Points: 25

Up
0
Down
Check the sample created by me, its working.
Pls change your code accordingly.


Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/19/2011 [Member] Starter | Points: 25

Up
0
Down
Ok.I will change and see

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/19/2011 [Member] Starter | Points: 25

Up
0
Down
HI
I have 3 fields Firstname,lastname,middle name in at table .Now i want to CONCATENATE first name and last name and display it under a single column field separated by a horizontal line.How to do this is this query works fine
select FName+'-'+MName Name from Example to get the output.Help me in ths issue.Help me by taking ex

First name
Vijaya
Last Name
Lakshmi
O/p
Name
vijaya
lakshmi

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/24/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
I am getting the state and country id's,But the dropdown items are bounded twice with states and cities .How to clear them.I used AppendDataBoundItems="false" for dropdown .How to solve this problem help me

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/24/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Thank U Very much for suggesting to complete the work.My problem has been solved

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 6/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
I have 4 tables with names personal details,company details and new branch,designations.Now i want to bind data to a radiolist from these 4tables by concatinating the first name,lastname and,designation name.I should display the branch name and the employees under the branch
[CompanyDetails] ----->[EmployeeId],[BranchId]
Branch Table------->[Branch Name,Branch Id]

Personal Table-----First Name,LastName,Middle Name
Designation----->designationid,designation name


Ex
HimayatNagar {Branch Name}
VijayaLakshmi(counsellor)

-----Branch2

============
vijaya is firstname,lakshmi is last name,counselor is designation name
please help me in writing the query





[UserName]







vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response