I have a dropdownlist which I populate from a db table and its value is in one column and the display text is in another. When I run my report I do a join to get the text to display on the page based on the value column. Here is my query:
SELECT fcomp_assign, (SELECT fcode_cmmt FROM fcode_mstr WHERE fcode_value = fcomp_assign AND fcode_fldname = 'fcomp_assign') AS AssignedTo FROM fcomp_mstr WHERE fcomp_comp_id = 8This returns what I expect: 6 and Customer Service
Problem is I want to populate the list with this query:
SELECT fcode_cmmt, fcode_value FROM fcode_mstr WHERE fcode_fldname = 'fcomp_assign'Which returns this:
Shipping 1
Purchasing 2
Inventory Control 3
Quality 4
Engineer Services 5
Customer Service 6
Production 7
Accounting 8And assign the selected value with the previous query from a different data source. I am sure it is possible but I haven't been able to find out how.
Remember to mark as answer if this post answered your question.
![]() |
0 |
![]() |
Your question is not clear. Do you want to implement a cascading drop-down - on seelction of one item from first Dropdown, it will populate second dropdown?
![]() |
0 |
![]() |
No the cascading part is easy to me. What I need to do is populate the ddl items with data from one table and the selected item value is a value stored in another table.
To take it a bit more in detail:
My complaint master table stores comp_assign = 3 for complaint_id #1. This would equal Inventory Control 3 in my code master table. I need to display the ddl text and store the ddl value which are in two seperate queries and tables.
Remember to mark as answer if this post answered your question.
![]() |
0 |
![]() |
Hi b471code3 ,
Do you want to set datatextfield and datavaluefield to two columns which in two different tables and there are FK relationship between these two tables ?
If so, my sample will be helpful.
DataSet ds = new DataSet(); DataTable catogory = new DataTable(); catogory.TableName = "cc"; catogory.Columns.Add("id"); catogory.Columns.Add("name"); DataRow dr1 = catogory.NewRow(); dr1["id"] = 1; dr1["name"] = "cat1"; catogory.Rows.Add(dr1); DataRow dr2 = catogory.NewRow(); dr2["id"] = 2; dr2["name"] = "cat2"; catogory.Rows.Add(dr2); DataTable item = new DataTable(); item.TableName = "ii"; item.Columns.Add("parent"); item.Columns.Add("name"); DataRow dr3 = item.NewRow(); dr3["parent"] = 1; dr3["name"] = "item1cat1"; item.Rows.Add(dr3); ds.Tables.Add(catogory); ds.Tables.Add(item); DataRelation rel = new DataRelation("test", ds.Tables["cc"].Columns["id"], ds.Tables["ii"].Columns["parent"]); ds.Relations.Add(rel); for (int i = 0; i < ds.Tables["ii"].Rows.Count; i++) { ListItem ditem = new ListItem(); ditem.Text = ds.Tables["ii"].Rows[i]["name"].ToString(); DataRow parent = ds.Tables["ii"].Rows[i].GetParentRow("test"); ditem.Value = parent["name"].ToString(); this.DropDownList1.Items.Add(ditem); }
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
0 |
![]() |
Hi
As per my understanding you have to populate the datatext and datavalue to the DDL and code is here
And if i am wrong plz let me know
Dim cmd As OdbcCommand = New OdbcCommand("select * from states where country_id=" & country.SelectedValue & " order by state_name", con) con.Open() Dim myreader As Odbc.OdbcDataReader myreader = cmd.ExecuteReader() Do While myreader.Read() Dropdownlist1.Items.Add(New ListItem(myreader("Datatext_column"), myreader("DataValue_Column"))) Loop myreader.Read()If you have a problem with this plz let me know
Thanks
~Avinash desai~
Software Developer
Bangalore
Please remember to click "Mark as Answer" on this post if it helped you.
![]() |
0 |
![]() |
This does look like what I am going for. What I have is a Complaint table with many fields, one of them being the AssignedTo value (INTEGER) which is joined back to a Code table which holds all the items for the DDL. So when I populate my DDL I run this query: SELECT * FROM CodeMstr WHERE CodeName = "CompAssign".
This returns: (dataText, dataValue)
Shipping, 1
Customer Service, 2
Purchasing, 3
etc.....What I want is to have the selected value be "Shipping" when the complaint has the AssignedTo value of 1 in that field. If I see what you are doing, I need to pass the AssignedTo value as a parameter to my SP in order to get the selected value to work right. Is this correct?
Remember to mark as answer if this post answered your question.
![]() |
0 |
![]() |
Hi
I think Yes... the way you wanted the above code does and see the query
b471code3:
SELECT * FROM CodeMstr WHERE CodeName = "CompAssign".
For displaying in the DDL it takes shipping and value will be one ...........If you have any question on this plz feel free to ask
Thanks
~Avinash desai~
Software Developer
Bangalore
Please remember to click "Mark as Answer" on this post if it helped you.
![]() |
0 |
![]() |