Dropdownlist assign selected value

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 = 8

 This 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 8

 And 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.


View Brenden Kehren's profile on LinkedIn
Remember to mark as answer if this post answered your question.
0
b471code3
4/7/2008 5:05:00 AM
asp.net.presentation-controls 72751 articles. 1 followers. Follow

7 Replies
154 Views

Similar Articles

[PageSpeed] 19

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
hemantksh
4/7/2008 5:44:30 AM

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.


View Brenden Kehren's profile on LinkedIn
Remember to mark as answer if this post answered your question.
0
b471code3
4/7/2008 5:53:54 AM

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
Samu
4/8/2008 10:16:19 AM

So I have tried your example in my setting and have not yet been able to be successful.  Is there no other way to do this within the GUI interface?  Does it all have to be done programatically?


View Brenden Kehren's profile on LinkedIn
Remember to mark as answer if this post answered your question.
0
b471code3
4/13/2008 8:52:40 PM

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
Avinash
4/14/2008 4:07:04 AM

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?


View Brenden Kehren's profile on LinkedIn
Remember to mark as answer if this post answered your question.
0
b471code3
4/14/2008 4:28:58 AM

 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
Avinash
4/14/2008 4:36:12 AM
Reply:

Similar Artilces:

assign data to other controls after select value from dropdownlist
Hello, In the webform, there is one dropdownlist and some text boxes. what i want to do is: once i select one of value from the list, for exsample, employee name, then, his profile, like date of birth, address, phone .. will show in other textbox, my question is, which dropdownlist event i should us? how to assign data to the controls? I am new to ASP. Thank for help in advance. You will have to handle SelectedIndexChanged event and do your save there. Just double click on it in your webform and it will create the event.Sonu Kapoor [MVP] Feel free to ask me any .NET question | Ajax Data Co...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

how can i Fill the controls on web page by selecting value from dropdownlist control.
  Hi,  Currentlly i am working on a web application where i require to fill the web form with the selected item in a text box. for example i have dropdown control named supplier_name, and i want to fill all the other controls values from database on the form when i select name from that supplier_name box,i.e , if i select name1, then related to that name, its code,address ,city should appear on related text boxes. I have done the same in windows application with c# , but the problem with web application(asp.net) is that, when i select Supplier _ it...

How to assign string value to dropdownlist when selected value field is an int(id of item)
 Hi i have a problem.In one of my application i am maintaining all controlvalues on a page in session using AJAX.i have done it.My page contain two dropdownlist.Data value field of items in dropdownlist is nothing but the idof items,i am retriving an selected item name from database using its id fromdatabase.once i got name the problem is that how can i give selected item of ddlistis the item name. i am triedddlist.SelectedValue=session("name")\\it gives nullddlist.SelectedItem.Text=session("name")\\\it gives object reference not set to instance of object erro...

DropDownList selected value determines value of second DropDownList
I have a quick question that I'm sure has been addressed before, but I can't seem to find a solution. I have two drop down list fields: startTime and endTime coded as such: <asp:DropDownList id="startTime" runat="server"> <asp:ListItem Value="00:00">12:00 A.M.</asp:ListItem> <asp:ListItem Value="00:30">12:30 A.M.</asp:ListItem> <asp:ListItem Value="01:00">1:00 A.M.</asp:ListItem> <asp:ListItem Value="...

Select dropdownlist control value
Hi, I have created a dropdownlist dynamically and populated it with numbers from 1 to 10. I also have a submit button on my page which when clicked is supposed to get the number I have selected in my dropdownlist. But this does not happen. It keeps returning 1 even if I select 4. I'm guessing whenever the page is loaded the dropdownlist is being created again and hence it selects the first number which is 1. Can anyone tell me how to solve this problem? How do I get the value of the number I have selected from a dropdownlist which is created dynamically? Thanks in advance for ...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

VB.NET
I have a DataGrid (see code at end of my question) with several dropdownlist controls within TemplateColumns for Editing.  For the first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like to populate ddlMedicationName based on the selecteditem of ddlMedType, but I don't know how to reference this. Thank you for saving me from confusion!!!! Here is my DataGrid code: NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!! ================== <asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateComm...

Not able to select value from dropdownlist control
I used sql server database with the multiple table connectivity. I created view to join three table and created stored procedure to fill dropdownlist control. I filled dropdownlist control succesfully but I am not able to select value from dropdownlist either by selectedItem.value or selectedItem.text. It selects first value only. <asp:TableCell VerticalAlign="Top"> <asp:DropDownList ID="NewDistNameNo" Runat="server" Width="100%" DataTextField="dist_name_no" DataValueField="office_id" AutoPostBack="True&quo...

Option to have no value selected in DropDownList control?
Whenever I DataBind a DropDownList, the list is already defaulted to a default value. I would like to user to have the option of not choosing anything from the dropdown list. The first line of the dropdown should be "-- Select --" or something similar. How can I accomplish this? When the user submits the form, no value should be passed for that input... I just can't get this to work at all. after binding the records from your database into your dropdownlist, add this code: DropDownList1.Items.Insert(0, "-- Select --") DropDownList1.SelectedIndex = 0 mes...

dropdownlist's selected index value is not printing the selected value
Here iS my code .Aspx Page <asp:DropDownList ID="ddlkeyword" runat="server" Width="204px" DataTextField="Form" DataValueField="Form" OnSelectedIndexChanged="ddlkeyword_SelectedIndexChanged" >   </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="Submit" Width="110px" OnClick="Button1_Click" /> my aspx.cs protected void Page_Load(object sender, EventArgs e) { fillddlkeyword(); }protected void Page_Init(object sender, EventArgs e) { ...

DROPDOWNLIST DOES NOT SELECT THE SELECTED VALUE
Hi all, i am using C# , asp.net vs2005. ajax 1.0 i am populating data programitically . when i select first value, dropdown control select the same. when i select second value ,dropdownlist select second value too But i does not continue  from third value onward . when i select third value, dropdownlist control select second value then after behavior reman the same no matter what i select dropdownlist control select second value ONLY.<asp:DropDownList id="Ddlzse" runat="server" Width="165px" Font-Bold="False" Fo...

Problem in Using DropDownList Control to select a selected row of SqlDataSource that is under GridView Control
Hi all,In my SQL Server Management Studio Express, I have a database "ChemDatabase" that has a table "LabData"  formatted in the following way: SampleID int PRIMARY KEY, SampleName nvarchar(25), ChemicalName, nvarchar(25), Concentration decimal(6.2) with 5 rows of records in this .dbo table. In my Visual Web Developer Express, I created a website "RPD-TCE" for extracting a row of record from the LabData table by using a DropDownList, a GridView and a SqlDataSource.  I want to click DropDownList to list one number of S...

Web resources about - Dropdownlist assign selected value - asp.net.presentation-controls

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 11/23/2015 12:12:11 AM