Setting DropDown datasource

Discussion in 'ASP .Net' started by David C, Jun 19, 2008.

  1. David C

    David C Guest

    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
    David C, Jun 19, 2008
    #1
    1. Advertising

  2. David C

    Mike L Guest

    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" wrote:

    > 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
    >
    >
    >
    Mike L, Jun 20, 2008
    #2
    1. Advertising

  3. David C

    David C Guest

    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" <> wrote in message
    news:...
    > 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" wrote:
    >
    >> 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
    >>
    >>
    >>
    David C, Jun 20, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul

    Datasource in a dropdown list

    Paul, Apr 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    352
    Scott Hamlin
    Apr 27, 2004
  2. =?Utf-8?B?TWVyZGFhZA==?=
    Replies:
    5
    Views:
    5,857
    neskire
    Nov 7, 2006
  3. =?Utf-8?B?TWVyZGFhZA==?=
    Replies:
    0
    Views:
    353
    =?Utf-8?B?TWVyZGFhZA==?=
    Oct 20, 2004
  4. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    datasource values and dropdown list

    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, May 6, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    600
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
    May 6, 2006
  5. =?Utf-8?B?VEpIZXJtYW4=?=

    Getting value of field in dropdown datasource within Formview

    =?Utf-8?B?VEpIZXJtYW4=?=, Jun 19, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    589
    =?Utf-8?B?VEpIZXJtYW4=?=
    Jun 19, 2006
Loading...

Share This Page