Setting DropDown datasource

  • Thread starter Thread starter David C
  • Start date Start date
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
 
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.
 
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
 
Back
Top