This is a migrated thread and some comments may be shown as answers.

RadGrid insert record issue with dropdownlist

2 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
d-cpt
Top achievements
Rank 2
d-cpt asked on 18 May 2017, 02:29 PM

Hi:

I have a radgrid with auto ops. Add/edit using template. Update works but Insert get this error:

"Get error when insert new record as "'ddlInstType' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"

Hopefully you give me a hint to fix this error.

Thank you.

 

 

Codes:

<telerik:RadGrid ID="rgInst" runat="server" CellSpacing="0" GridLines="None" RenderMode="Lightweight"
      AllowAutomaticUpdates="True" AllowAutomaticInserts="True" AllowAutomaticDeletes="true" AutoGenerateColumns="false" DataSourceID="sdsInst"
      OnItemCreated="rgInst_ItemCreated" OnItemInserted="rgInst_ItemInserted" OnItemUpdated="rgInst_ItemUpdated" OnItemDeleted="rgInst_ItemDeleted" OnItemCommand="rgInst_ItemCommand">
      <PagerStyle Mode="NextPrevNumericAndAdvanced" />
      <GroupingSettings CaseSensitive="false" />
      <MasterTableView AutoGenerateColumns="false" DataSourceID="sdsInst" DataKeyNames="InstID, InstTypeId" CommandItemDisplay="Top" EditMode="EditForms">
        <Columns>
          <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />          
          <telerik:GridBoundColumn UniqueName="InstName" DataField="InstName" HeaderText="Institution" />
          <telerik:GridBoundColumn DataField="InstOffice" HeaderText="School/Dept." />
          <telerik:GridBoundColumn UniqueName="InstTypeDesc" DataField="InstTypeDesc" HeaderText="Campus Type" />
          <telerik:GridButtonColumn Text="Deactivate" CommandName="Delete" ConfirmText="Deactivate this record?" />
        </Columns>

        <EditFormSettings EditFormType="Template">
          <FormTemplate>
            <br />
                  <table class="tableW100">
                    <tr>
                      <td class="td30R">Institution name:</td>
                      <td class="td70L">
                        <asp:TextBox ID="tbInstName" runat="server" CssClass="tbW100" Text='<%# Bind("InstName") %>' />
                      </td>
                    </tr>
                    <tr>
                      <td class="td30R">School/Department:</td>
                      <td class="td70L">
                        <asp:TextBox ID="tbInstOffice" runat="server" CssClass="tbW100" TextMode="MultiLine" Text='<%# Bind("InstOffice") %>' />
                      </td>
                    </tr>
                    <tr>
                      <td class="td30R">Campus Type:</td>
                      <td class="td70L">
                        <asp:DropDownList ID="ddlInstType" CssClass="tbW100" runat="server" DataSourceID="sdsInstType" DataTextField="InstTypeDesc" DataValueField="InstTypeID" SelectedValue='<%# Bind("InstTypeID") %>' />
                      </td>
                    </tr>                    
              <tr>
                <td colspan="2" class="tr4Btn">
                  <asp:Button ID="btnUpdate" CssClass="flatbtnFlexSmall" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' />&nbsp;
                  <asp:Button ID="btnCancel" CssClass="flatbtnFlexSmall" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" />
                </td>
              </tr>             
          </FormTemplate>
        </EditFormSettings>
      </MasterTableView>
    </telerik:RadGrid>

<asp:SqlDataSource ID="sdsInst" runat="server" ConnectionString="<%$ ConnectionStrings:MainDB %>"
    SelectCommand="sprInstitutionGet" SelectCommandType="StoredProcedure"
    UpdateCommand="sprInstitutionUpdate" UpdateCommandType="StoredProcedure"
    InsertCommand="sprInstitutionAdd" InsertCommandType="StoredProcedure"
    DeleteCommand="sprInstitutionDeactivate" DeleteCommandType="StoredProcedure">

    <InsertParameters> {...}
    </InsertParameters>

    <UpdateParameters>{...}
    </UpdateParameters>

    <DeleteParameters>{...}
    </DeleteParameters>

 </asp:SqlDataSource>

<asp:SqlDataSource ID="sdsInstType" runat="server" ConnectionString="<%$ ConnectionStrings:MainDB %>" SelectCommand="sprInstitutionTypeGet" SelectCommandType="StoredProcedure" />

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 23 May 2017, 06:06 AM
Hi,

Generally, the Bind method should work as expected. You can check the following live sample and compare it with your original application:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

Regards,
Eyup
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
d-cpt
Top achievements
Rank 2
answered on 23 May 2017, 12:57 PM
Eyup,

 

Thanks for the reply.

I think the "trick" to make it work here is using AppendDataBoundItems.

This attribute along with <asp:ListItem Selected="True" Text="Select..." Value="" /> helps to bypass the error of binding value to dropdownlist in insert.

Regards,

Duc

 

 

Tags
Grid
Asked by
d-cpt
Top achievements
Rank 2
Answers by
Eyup
Telerik team
d-cpt
Top achievements
Rank 2
Share this question
or