Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to default drop down list to a specific value

Author  Topic 

emyk
Yak Posting Veteran

57 Posts

Posted - 2014-10-21 : 09:19:03
I have a drop down list that is populated by a stored procedure which has two int parameters (ID, STATUS). I need to default the drop down list to a value in the database that is associated to the ID & STATUS parameters.

The problem I am having is that it only works if the selected value is the first record on the drop down list. for any other records (outside the first record) from the drop down list i get "The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive."

Here is the stored procedure I am using to populate the drop down list:

ALTER PROCEDURE [dbo].[usp_SelectName]
(
@pId Int,
@pStatus Int
)
AS
BEGIN
IF @pId = -1 --THIS VALUE IS USED AS DEFAULT (NOT POSTBACK)
BEGIN
if @pStatus <> -1
BEGIN
SELECT * FROM TABLE_NAMES WHERE IN_STATUS = @pStatus

ORDER BY IN_NAME
END
ELSE
BEGIN
SELECT * FROM TABLE_NAMES ORDER BY IN_NAME
END
END
ELSE
BEGIN
SELECT * FROM TABLE_NAMES
inner join TABLE_2
ON TABLE_2.IN_ID = TABLE_NAMES_IN_ID
WHERE IN_ID = @pId
END
END



Here is the TABLE_NAMES that holds the data for the drop down list:

IN_ID IN_NAME STATUS
6 New 0
4 Generic 0
3 Local 1
4 Storm 0



This is the TABLE_2 that holds the complete collected FORM data that has the selected record IN_ID from the TABLE_NAME:


ID STATUS IN_ID
1119 0 6
1144 0 6
1145 0 5
1146 0 6
1147 0 6

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-21 : 09:27:47
I think your problem is in the application, not the stored procedure.
Go to Top of Page

emyk
Yak Posting Veteran

57 Posts

Posted - 2014-10-21 : 09:52:47
the error I am getting is an application error, I think I have traced the source that is causing the issue is the SP. I am also looking from the application front to see if I can catch it.
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-21 : 09:59:39
THe problem is that the application is not properly handling the results of the SP. Run the SP by itself with the various options and see what you get, then examine (or trace) the application to see what it does in each case.


BTW, 'SELECT *' is considered bad form and can lead to problems (what if new columns are added to TABLE_NAMES?)
Go to Top of Page

emyk
Yak Posting Veteran

57 Posts

Posted - 2014-10-21 : 11:24:58
I found the problem in the application. All working good now:)
thank you!!
Go to Top of Page
   

- Advertisement -