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

  • Question

  • User-1130060346 posted

    I get the following error when i try edit my grid. I know the reason behind the issue but i can't seem to fix my problem. The problem is that, when the user hits edit, the current value of dropdownlist value doesn't exist in the datasource.

    The following is my datasource that populates the dropdownlist. I hard coded the number '4' in my sql query just to test a row. It works fine when i hard code it. What I want to do is replace the '4' with a paramater of the current dropdownlist list value (Which I tried but I can't get it to work) or add the current dropdownlist list value to the datasource. I tried to replace the '4' with @tran_pk and in my <selectParameters> section i added <asp:parameters name="tran_pk" type=int32 /> and that didn't work. ANY suggestions?

        <asp:SqlDataSource ID="TypeSource" runat="server"
     
        SelectCommand="SELECT DISTINCT  tran_pk, tran_desc FROM loanpayoff.dbo.tran_type
     where tran_pk NOT IN (select tran_fk from  fund_alloc where ltrim(note_id) = @noteid)
     or tran_pk = 4 ORDER BY tran_desc">
       
            <SelectParameters>
            <asp:QueryStringParameter Name="noteid" QueryStringField="noteid" type=string ConvertEmptyStringToNull="false"/>
            </SelectParameters>

        </asp:SqlDataSource>

     Code for the dropdownlist:

    <asp:BoundField HeaderText="tran_pk" DataField="tran_pk" Visible = "false" ReadOnly = "true" />
     
    <asp:TemplateField HeaderText="Type" SortExpression="tran_desc">
          <ItemTemplate>
              <asp:Label ID="lblEditType" Text='<%# Eval("tran_desc") %>' Runat="Server"/>
          </ItemTemplate>
          <EditItemTemplate>
              <asp:DropDownList id="EditType" DataSourceID="TypeSource" Runat="Server"
                  DataTextField="tran_desc" DataValueField="tran_pk" SelectedValue='<%# Bind("tran_pk")%>'/>
          </EditItemTemplate>
    </asp:TemplateField>

    Monday, October 15, 2007 3:43 PM

All replies