Setting DropDown datasource

D

David C

I have a GridView with a DropDownList control that is tied to an
SqlDataSource. It pulls from a table/view of staff people and is a
data-bound control linked to an ID column in the GridView data source. I
want to be able to show only the active staff people in the DropDownList.
However, if I edit an old record with an ID tied to an inactive staff member
then the asp.net page throws an exception.

How do I best get around this so that I can show only the current ID staff
person and all the other "active" staff people? And where is the best place
to change my data source? I only care if I am editing the row. Below is my
data source SQL. Thanks.

<asp:SqlDataSource ID="SqlvwStaffPick" runat="server"
ConnectionString="<%$ ConnectionStrings:FiledataConnectionString %>"
SelectCommand="SELECT [PersonID], [Person] FROM [vw_StaffPick]
ORDER BY [Person]">
</asp:SqlDataSource>

David
 
M

Mike L

Does your SQL statement contain the active flag? in your SQL?

Also you will need the find.control method when trying to use the dropdown
in the gridview container. I hope this helps.
 
D

David C

Yes, but my biggest concern is where can I reset the datasource so that I do
not get an exception? I want to be able to get all "active" as well as the
ID currently in the underlying datasource, even if that person is not
currently active. For example
SELECT [PersonID], [Person] FROM [vw_StaffPick] WHERE Active = 1 OR PersonID
= <controlID> ORDER BY [Person]

Thanks.
David

Mike L said:
Does your SQL statement contain the active flag? in your SQL?

Also you will need the find.control method when trying to use the dropdown
in the gridview container. I hope this helps.

David C said:
I have a GridView with a DropDownList control that is tied to an
SqlDataSource. It pulls from a table/view of staff people and is a
data-bound control linked to an ID column in the GridView data source. I
want to be able to show only the active staff people in the DropDownList.
However, if I edit an old record with an ID tied to an inactive staff
member
then the asp.net page throws an exception.

How do I best get around this so that I can show only the current ID
staff
person and all the other "active" staff people? And where is the best
place
to change my data source? I only care if I am editing the row. Below is
my
data source SQL. Thanks.

<asp:SqlDataSource ID="SqlvwStaffPick" runat="server"
ConnectionString="<%$ ConnectionStrings:FiledataConnectionString %>"
SelectCommand="SELECT [PersonID], [Person] FROM
[vw_StaffPick]
ORDER BY [Person]">
</asp:SqlDataSource>

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top