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

DropDownList and Edit/Insert mode URGENT!!

3 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 16 Jul 2008, 04:22 AM
I have tried all the demos and examples and nothing has worked!
Markup:
<telerik:RadGrid ID="grvUsers"   
                     runat="server"   
                     AutoGenerateColumns="False"   
                     GridLines="None" 
                     Skin="Office2007"   
                     OnNeedDataSource="grvUsers_NeedDataSource"   
                     OnUpdateCommand="grvUsers_UpdateCommand"   
                     AllowPaging="True"   
                     AllowSorting="True"   
                     ShowGroupPanel="True" OnItemCommand="grvUsers_ItemCommand" OnEditCommand="grvUsers_EditCommand">  
        <MasterTableView AllowAutomaticInserts="True" CommandItemDisplay="Top">  
            <RowIndicatorColumn Visible="False">  
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Resizable="False" Visible="False">  
                <HeaderStyle Width="20px" /> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridEditCommandColumn> 
                </telerik:GridEditCommandColumn> 
                <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="LastName">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="FirstName">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="UserLevel" HeaderText="User Rights" UniqueName="Rights">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Enabled" HeaderText="Enabled" UniqueName="Enabled">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="UserInfoUID" UniqueName="UserInfoUID" Visible="False">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="UserName" UniqueName="UserName" Visible="False">  
                </telerik:GridBoundColumn> 
            </Columns> 
            <EditFormSettings EditFormType="Template" CaptionFormatString="Edit the information for &lt;%# Bind('FirstName') %&gt; &lt;%# Bind('LastName') %&gt;" > 
                <EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
                <FormTemplate> 
                    <table style="width: 568px">  
                        <tr> 
                            <td style="width: 131px">  
                                Last Name</td> 
                            <td style="width: 160px">  
                                <telerik:RadTextBox ID="txtEdit_LastName" runat="server" MaxLength="50" Text="<%# Bind('LastName') %>">  
                                </telerik:RadTextBox></td>  
                            <td> 
                                <asp:RequiredFieldValidator ID="rfvEdit_LastName" runat="server" ControlToValidate="txtEdit_LastName" 
                                    ErrorMessage="Please enter the users last name" ValidationGroup="Edit">*</asp:RequiredFieldValidator> 
                            </td> 
                            <td style="width: 174px">  
                                First Name</td> 
                            <td style="width: 156px">  
                                <telerik:RadTextBox ID="txtEdit_FirstName" runat="server" MaxLength="50" Text="<%# Bind('FirstName') %>">  
                                </telerik:RadTextBox></td>  
                            <td> 
                                <asp:RequiredFieldValidator ID="rfvEdit_FirstName" runat="server" ControlToValidate="txtEdit_FirstName" 
                                    ErrorMessage="Please enter the users first name" ValidationGroup="Edit">*</asp:RequiredFieldValidator></td>  
                        </tr> 
                        <tr> 
                            <td style="width: 131px">  
                                Username</td> 
                            <td style="width: 160px">  
                                <telerik:RadTextBox ID="txtEdit_Username" runat="server" Text="<%# Bind('Username') %>">  
                                </telerik:RadTextBox></td>  
                            <td> 
                                <asp:RequiredFieldValidator ID="rfvEdit_UserName" runat="server" ControlToValidate="txtEdit_Username" 
                                    ErrorMessage="Please enter the users 'Username'" ValidationGroup="Edit">*</asp:RequiredFieldValidator></td>  
                            <td style="width: 174px">  
                            </td> 
                            <td style="width: 156px">  
                            </td> 
                            <td> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td style="width: 131px; height: 27px">  
                                Password</td> 
                            <td style="width: 160px; height: 27px">  
                                <telerik:RadTextBox ID="txtEdit_Password" runat="server" InvalidStyleDuration="100" Text="<%# Bind('Password') %>" Width="125px" EmptyMessage="************" MaxLength="20" TextMode="Password">  
                                </telerik:RadTextBox></td>  
                            <td style="height: 27px">  
                            </td> 
                            <td style="width: 174px; height: 27px">  
                                Password</td> 
                            <td style="height: 27px; width: 156px;">  
                                <telerik:RadTextBox ID="txtEdit_ConfirmPassword" runat="server" InvalidStyleDuration="100" Text="<%# Bind('Password') %>" TextMode="Password" Width="125px" EmptyMessage="***********" MaxLength="20">  
                                </telerik:RadTextBox> 
                            </td> 
                            <td style="height: 27px">  
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                Rights</td> 
                            <td> 
                                <asp:DropDownList ID="cmbEdit_Rights" runat="server" Width="119px" SelectedValue='<%# Bind("UserLevel") %>'>  
                                    <asp:ListItem>User</asp:ListItem> 
                                    <asp:ListItem>Admin</asp:ListItem> 
                                </asp:DropDownList></td>  
                            <td> 
                            </td> 
                            <td> 
                                Enabled</td> 
                            <td> 
                                <asp:DropDownList ID="cmbEdit_Enabled" runat="server" Width="119px" SelectedValue='<%# Bind("Enabled") %>'>  
                                    <asp:ListItem Value="True">Yes</asp:ListItem> 
                                    <asp:ListItem Value="False">No</asp:ListItem> 
                                </asp:DropDownList></td>  
                            <td> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td colspan="6">  
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="right" colspan="6">  
                                <asp:LinkButton ID="lnkEdit_Cancel" runat="server" CausesValidation="False" CommandName="Cancel" Text='<%# (Container is GridEditFormInsertItem) ? "Done" : "Cancel" %>' >Cancel</asp:LinkButton>&nbsp;  
                                &nbsp;<asp:LinkButton ID="lnkEdit_Done" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' Text='<%# (Container is GridEditFormInsertItem) ? "Save" : "Save Changes" %>'></asp:LinkButton> 
                                &nbsp;  
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="center" colspan="6">  
                                <asp:Label ID="lblUID" runat="server" Text="<%# Bind('UserInfoUID') %>" Visible="False"></asp:Label> 
                                <asp:Label ID="lblEdit_Message" runat="server"></asp:Label> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="center" colspan="6" style="height: 21px">  
                                <asp:ValidationSummary ID="vsEdit" runat="server" ValidationGroup="Edit" /> 
                            </td> 
                        </tr> 
                    </table> 
                </FormTemplate> 
                <PopUpSettings ScrollBars="None" /> 
            </EditFormSettings> 
            <CommandItemSettings AddNewRecordText="Add new user" /> 
            <PagerStyle AlwaysVisible="True" HorizontalAlign="Left" Mode="Slider" /> 
        </MasterTableView> 
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowDragToGroup="True">  
            <Selecting AllowRowSelect="True" /> 
        </ClientSettings> 
    </telerik:RadGrid> 

Now, heres where it works and doesn't. If I have this line (similar for the second drop down):
 <asp:DropDownList ID="cmbEdit_Enabled" runat="server" Width="119px" SelectedValue='<%# Bind("Enabled") %>'>  
                                    <asp:ListItem Value="True">Yes</asp:ListItem> 
                                    <asp:ListItem Value="False">No</asp:ListItem> 
                                </asp:DropDownList> 
when I go into edit mode, the drop downs are populated with the current values which is a project requirement.  But when I click the 'Add new user', I get this error:

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

If I leave out the <%# Bind("UserLevel") %> I can insert and update, but I loose the requirement of displaying the current value which I need.


Please help asap!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Jul 2008, 05:02 AM
Hi Tim,

The reason for this error is that your grid instance can not bind a value for the newly inserted item through the Eval()/Bind() syntax you hard-coded (as you may have seen from the stack trace of the error). Go through the following help article to get details on fixing this error.

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


Thanks
Shinu.
0
Allan
Top achievements
Rank 2
answered on 28 Feb 2012, 05:17 PM
Shinu,

I have this exact came issue, unfortunately your link no longer works. Does the article still exist?
0
Shinu
Top achievements
Rank 2
answered on 29 Feb 2012, 04:13 AM
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Allan
Top achievements
Rank 2
Share this question
or