Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dropdown list - set selected item from query

Posted on 2013-06-05
4
Medium Priority
?
293 Views
Last Modified: 2013-06-18
Hi,

I have a .net page with a ddl.
The datasource query for the ddl is
select tbGroupDiscount.iGroupDiscountid, vGroupname,iProductid from tbGroupDiscount left join tbProductDiscount
on tbProductDiscount.iGroupDiscountid = tbGroupDiscount.iGroupDiscountid and iProductid = @iProductid where iClientid = @iClientid order by vGroupname

 <asp:DropDownList ID="ddlGroupDiscount" runat="server" AutoPostBack="true" AppendDataBoundItems="true"   DataSourceID="GetGroupDiscount" DataTextField="vGroupname" DataValueField="iGroupDiscountid" >
                <asp:ListItem Value="0" Text="Please Select"></asp:ListItem>

after I call databind in my cs, I wish to select an item if there's a value for productid returned in the query
eg query could return

1, group1, null
2, group2, null
3, group3, 99
4, group4, null

null/99 being the productid from the query above.. so if the query has a value for productid I'd like that item to be selected

any ideas welcome?

Cheers
0
Comment
Question by:louise_8
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
ID: 39225724
Hi,

You may have loop through the values returned from the database and check for the value and update the value as selected for the DropDownList.

You can set the value - DropDownList.SelectedValue - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue.aspx

Hope it helps u...
0
 

Author Comment

by:louise_8
ID: 39240115
Thanks
I suppose I'm confused because my ddl has a datasource and binds as the page is run
So because I dont create the listitems in the code behind does that mean I need to bind using the code behind or is there a way to select after its initallu bound?

Cheers
0
 
LVL 23

Assisted Solution

by:Roopesh Reddy
Roopesh Reddy earned 500 total points
ID: 39253992
Hi,

So, if the data is already binded, then you may have to loop through the list items and select the desired option!

Hope it helps u...
0
 

Author Closing Comment

by:louise_8
ID: 39258118
thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question