locked
'ddlAvailableYN' has a SelectedValue which is invalid because it does not exist in the list of items. RRS feed

  • Question

  • User497225302 posted

    This of course is a frequent post but I cannot find any posts that I can use... I checked my SQL table to make sure there were no nulls or other data than Yes or No...

    I have a gridview with a template field containing a DropDownList... when I hit my "Edit" button I get this message:

    'ddlAvailableYN' has a SelectedValue which is invalid because it does not exist in the list of items.
    Parameter name: value

    any ideas? - Below is the relevant code:

    <asp:SqlDataSource
        ID="SqlDataSource1"
        runat="server"
        connectionstring="<%$ ConnectionStrings:TrackITConnectionString %>"
        selectcommand="SELECT [Unit_Price], [Software_Description], [EndUserFirstName], [License_Available],
        [LAN_ID], [EndUserLastName], [Transaction_Number], [Transaction_Type], [HeatTicketNumber]
        FROM [tblTransactions]
        WHERE (([TransferedSoftware] IS Null) AND ([EndUserLastName] = @EndUserLastName) AND ([Transaction_Type] <> 'Transfer')) ORDER BY [EndUserFirstName]"
        UpdateCommand="UPDATE [tblTransactions] SET [License_Available] = 'No'
        WHERE [Transaction_Number] = @Transaction_Number">
        <SelectParameters>
            <asp:ControlParameter ControlID="txtLastname" Name="EndUserLastName"
                PropertyName="Text" Type="String" />
        </SelectParameters>
                    <UpdateParameters>
                          <asp:Parameter Name="[License_Available]" Type="String" />
                          <asp:Parameter Name="[Transaction_Number]" Type="String" />
                    </UpdateParameters>
    </asp:SqlDataSource>

    <ItemStyle HorizontalAlign="Center" Width="100px" CssClass="gridview_body_font" BorderStyle="Inset"></ItemStyle>
            </asp:BoundField>
                          <asp:TemplateField HeaderText="Available" SortExpression="License_Available">
                              <EditItemTemplate>
                                 <asp:DropDownList ID="ddlAvailableYN" runat="server"
                                              Width="100px" Text='<%# Bind("License_Available") %>' AppendDataBoundItems="True">
                                       <asp:ListItem Value="True">No</asp:ListItem>
                                       <asp:ListItem Value="False">Yes</asp:ListItem>
                                 </asp:DropDownList>
                              </EditItemTemplate>
                              <ItemTemplate>
                                  <asp:Label ID="Label2" runat="server" Text='<%# Bind("License_Available") %>'></asp:Label>
                              </ItemTemplate>
                              <ItemStyle BorderStyle="Inset" CssClass="gridview_body_font"
                                  HorizontalAlign="Center" Width="100px" />
                            </asp:TemplateField>
                    <asp:BoundField DataField="Transaction_Number" HeaderText="Trans #"
                SortExpression="Transaction_Number" ReadOnly="True" ItemStyle-HorizontalAlign="Center"
                HtmlEncode="False" ItemStyle-Width="700" ApplyFormatInEditMode="True">
    <ItemStyle HorizontalAlign="Center" Width="100px" CssClass="gridview_body_font" BorderStyle="Inset"></ItemStyle>

    Monday, December 3, 2012 11:12 AM

Answers

  • User1495804863 posted

    Hi,

    Check that column License_Available having "Yes" or "No" in your database, I think it returning some value which is not there in the dropdownlist....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2012 11:23 AM
  • User1495804863 posted

    Hi,

    Then try like the following

    <asp:DropDownList ID="ddlAvailableYN" runat="server" 
    Width="100px" SelectedValue ='<%# Bind("License_Available") %>' AppendDataBoundItems="True">
    <asp:ListItem Value="True">No</asp:ListItem>
    <asp:ListItem Value="False">Yes</asp:ListItem>
    </asp:DropDownList>


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2012 11:41 AM

All replies

  • User1495804863 posted

    Hi,

    Check that column License_Available having "Yes" or "No" in your database, I think it returning some value which is not there in the dropdownlist....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2012 11:23 AM
  • User497225302 posted

    Checked that and all are Yes or No

    Monday, December 3, 2012 11:25 AM
  • User1495804863 posted

    Hi,

    Then try like the following

    <asp:DropDownList ID="ddlAvailableYN" runat="server" 
    Width="100px" SelectedValue ='<%# Bind("License_Available") %>' AppendDataBoundItems="True">
    <asp:ListItem Value="True">No</asp:ListItem>
    <asp:ListItem Value="False">Yes</asp:ListItem>
    </asp:DropDownList>


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2012 11:41 AM
  • User622904130 posted

    add to your options:

      <asp:ListItem Value=""></asp:ListItem>

    Monday, December 3, 2012 11:43 AM
  • User497225302 posted

    Strangely now I get the error: BC30456: 'Gridview1_SelectedIndexChanged' is not a member of 'ASP.checkboxswlist_aspx'.

    <asp:gridview ID="Gridview1" runat="server" autogeneratecolumns="False" datakeynames="LAN_ID"

    Monday, December 3, 2012 11:56 AM