Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

ASP.Net/C# - Dropdownlist Question selected value

Hello all.  I have a dropdown list that gets bound to a dataset I have.  In that dataset there is a field called Primary and its either Y or N.  This field is in the dataset but not my DataValueField or DataTextField.  What I want to do is after the bind select the value that has the Primary = Y.  Any idea how I can do that after the bind?  thanks all
SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sbornstein2
sbornstein2

ASKER

dropdownObj.SelectedValue = "VALUE OF PRIMARY" would that be something like

dropdownObj.SelectedValue = "Primary = Y" or something?   Again the Primary is not actually the value field or the text field in the drop.
If you want to do it all with one SQL call you will have to loop through the DataReader and create each list item and check if it is primary or not. If you want to just use "dropdownObj.SelectedValue = "VALUE OF PRIMARY"" then you will need to do another SQL call to get the primary: SELECT TEXTFIELDCOLUMN FROM TABLE WHERE PRIMARY = 'Y'
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
actually I have a dataview is it the same code for the dataset?  thanks guys
I believe they are similar. Either way you should be able to loop through the set and find the Primary = Y and set the .SelectedValue equal to that rows value.
thank you