Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7048119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:51:12+00:00 2026-05-28T02:51:12+00:00

Well, I have GridView with editable field like ‘TemplateField’ with DropDownList. My code: <Columns>

  • 0

Well, I have GridView with editable field like ‘TemplateField’ with DropDownList.
My code:

<Columns>
    ...
    <asp:TemplateField SortExpression="Room" HeaderText="Room">
        <EditItemTemplate>
            <asp:DropDownList ID="DropDownList1" Runat="server" DataSourceID="categoryDataSource" DataTextField="RoomNumber" DataValueField="RoomNumber" SelectedValue='<%# Bind("Room") %>'>
            </asp:DropDownList>
        </EditItemTemplate>
    </asp:TemplateField>
    <ItemTemplate>
        <asp:Label Runat="server" Text='<%# Bind("Room") %>' ID="Label1"></asp:Label>
    </ItemTemplate>
</Columns>

My DB has table Rooms, which has rows: RoomId, RoomNumber.
In my DropDownList I try set all values from table Rooms.
Table has 3 rows (RoomId, RoomNumber): 1 – 20; 2 – 12; 3 – 24.

But write follow error:

'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.

Parameter name: value
Maybe anybody know where have I erred?

Edit: Here is the SQLDataSource code

<asp:SqlDataSource ID="categoryDataSource" Runat="server" 
    SelectCommand="SELECT [RoomId], [RoomNumber] FROM [Rooms] ORDER BY [RoomNumber]" 
    ConnectionString="Data Source=.\MSSQLSERVERR2;AttachDbFilename=|DataDirectory|\ARMDB.MDF;Integrated Security=True;User Instance=True">
</asp:SqlDataSource>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:51:13+00:00Added an answer on May 28, 2026 at 2:51 am

    The error indicates that the value that you are trying to set as selected into the drop-down list does not exist. I believe that this has happen mostly because not choosing a wrong field for value in drop-down list or setting wrong value.

    For example, in your case, most probably, you are storing RoomId (and not RoomNumber) in the referenced table, so you need to bind value field of drop-down list accordingly

    <asp:DropDownList ID="DDL1" Runat="server" DataSourceID="categoryDataSource" 
       DataTextField="RoomNumber" DataValueField="RoomId" 
       SelectedValue='<%# Bind("Room") %>'>
    

    Note DataValueField value – its RoomId and not room number. (Assuming Bind("Room") is going to return room id)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview which is like <asp:TemplateField HeaderText=File Name SortExpression=FileName> <ItemTemplate> <asp:LinkButton ID=lnkname
I have a gridview with a template field that has a HyperLink: <asp:TemplateField ItemStyle-Width=12%
Well i have a gridview where i have defined the columns on my own
I have a gridview were I define some columns, like this... <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock
I have built a dynamic gridview using the following code grdVariants.Columns.Clear(); int i =
I have the following GridView in ASP.NET 3.5: <asp:GridView ID=gvTable runat=server AllowSorting=true ShowHeader=true> <Columns>
I have a ASP.NET GridView that uses template columns and user controls to allow
well i have this messages table with sample values like these: msg_id recipient_id read
I'am building an asp.net application that have a gridview inside an update pannel. In
I have a ASP.NET GridView with a column mapped to a boolean. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.