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

Drop Down List error in FormTemplate

2 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 12 Feb 2015, 11:38 PM
I am getting an error:
'ddlWebPages' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value


This happens only when I click the Add New Record button on the grid. the ddlWebPages has no issues when I am in edit mode.
I believe this has to do the the snippet SelectedValue='<%# Bind("security_webpage_id") %> of the dropdownlist. 
I searched for solutions but none of them worked. There was one suggestion for SelectedValue='<%# Eval("security_webpage_id") == null ? null :  Eval("security_webpage_id") %>'. That didnt work for me. Has anyone dealt with this issue? HELP! I am so close to finishing my grid.



<telerik:RadGrid ID="RadGridwebpagemanagement" CssClass="webpageManagementGrid" MasterTableView-DataKeyNames="ID" runat="server"
            AllowFilteringByColumn="True" AllowSorting="True"
            GroupPanelPosition="Top" 
            OnNeedDataSource="RadGridwebpagemanagement_NeedDataSource"
            OnUpdateCommand="RadGridwebpagemanagement_UpdateCommand" OnItemDataBound="RadGridwebpagemanagement_ItemDataBound" OnDeleteCommand="RadGridwebpagemanagement_DeleteCommand" OnInsertCommand="RadGridwebpagemanagement_InsertCommand">
            <ClientSettings>
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add New Webpage" 
                 InsertItemPageIndexAction="ShowItemOnCurrentPage">
 
                <columns>
                     
                    <telerik:GridBoundColumn DataField="webpage_name" HeaderText="Web Page" UniqueName="webpage_name" ItemStyle-Font-Names="Arial" ItemStyle-Font-Bold="true"
                                FilterControlWidth="200px">
                                <HeaderStyle Width="230px" Font-Names="Arial" />
                                <ItemStyle Width="230px" />
                    </telerik:GridBoundColumn>
                    
                    <telerik:GridCheckBoxColumn DataField="add_privledge" HeaderText="Allow Adds" UniqueName="add_privledge"
                                FilterControlWidth="120px">               
                                <HeaderStyle Width="120px" Font-Names="Arial" />
                                <ItemStyle Width="120px" />
                    </telerik:GridCheckBoxColumn>
                     
                    <telerik:GridCheckBoxColumn DataField="edit_privledge" HeaderText="Allow Edits" UniqueName="edit_privledge"
                                FilterControlWidth="120px">               
                                <HeaderStyle Width="120px" Font-Names="Arial" />
                                <ItemStyle Width="120px" />
                   </telerik:GridCheckBoxColumn>
 
                     <telerik:GridCheckBoxColumn DataField="delete_privledge" HeaderText="Allow Deletes" UniqueName="delete_privledge"
                              FilterControlWidth="120px">               
                                <HeaderStyle Width="120px" Font-Names="Arial" />
                                <ItemStyle Width="120px" />
                    </telerik:GridCheckBoxColumn>                  
 
                   <telerik:GridEditCommandColumn ButtonType="LinkButton" EditText="Edit" CancelText="Cancel" ItemStyle-Width="50px" HeaderStyle-Width="50px" FilterControlWidth="50px" />
                   <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                        ConfirmTitle="Delete" ButtonType="LinkButton" Text="Delete" CommandName="Delete" ItemStyle-Width="50px" HeaderStyle-Width="50px" FilterControlWidth="50px" />
                     
                </columns>
                
                <EditFormSettings EditFormType="Template">
                <FormTemplate>   
                    
                   
                    <div id="divGridEdit" class="divGrid">
                            <b>Add New Role to Webpage Association</b>
                            <br /><br />
                            <table>
 
                                <tr>
                                    <td><asp:Label Text="Web Page:" runat="server"></asp:Label></td>
                                    <td>
                                         <asp:DropDownList ID="ddlWebPages"  DataSourceID="sqlDataSourceWebpages" AppendDataBoundItems="True"
                                                DataTextField="webpage_name" DataValueField="ID" SelectedValue='<%# Bind("security_webpage_id") %>'
                                                runat="server"> 
                                          
                                         </asp:DropDownList>
 
                                    </td>
                                </tr>
                                <tr>
                                     <td><asp:Label Text="Allow Add:" runat="server"></asp:Label></td>
                                     <td><asp:CheckBox ID="chkboxAllowAdd" Checked='<%# Bind("add_privledge") %>' runat="server" /></td>
                                </tr>
                                <tr>
                                     <td><asp:Label Text="Allow Edit:" runat="server"></asp:Label></td>
                                     <td><asp:CheckBox ID="chkboxAllowEdit" Checked='<%# Bind("edit_privledge") %>' runat="server" /></td>
                                </tr>
                                <tr>
                                     <td><asp:Label Text="Allow Delete:" runat="server"></asp:Label></td>
                                     <td><asp:CheckBox ID="chkboxDelete" Checked='<%# Bind("delete_privledge") %>' runat="server" /></td>
                                </tr>
                                <tr>
                                    <td><br /></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td><asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'  runat="server" /></td>
                                    <td><asp:Button ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" CausesValidation="false" /></td>
                                </tr>
                            </table>
                        </div>            
 
                </FormTemplate>
            </EditFormSettings>
 
 
            </MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowDblClick="rowDblClick" />
            </ClientSettings>
                
        </telerik:RadGrid>
 
 
    </div>
 
    <asp:SqlDataSource ID="sqlDataSourceWebpages" runat="server" SelectCommand="SELECT * FROM dbo.security_webpage" ConnectionString="<%$ ConnectionStrings:GATEConnectionString %>"></asp:SqlDataSource>
 
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" />

2 Answers, 1 is accepted

Sort by
0
davortsan
Top achievements
Rank 1
answered on 13 Feb 2015, 07:38 AM
Hi David,

I think your problem is the null value that you set to SelectedValue when the Eval("security_webpage_id") == null condition is true. If you set null to the DropDownList SelectedValue and Exception will be thrown. To test it, you could change that null and set to an existing ID in dbo.security_webpage. If the code is executed successfully, you should choose the default ID when Eval("security_webpage_id") == null. If it is possible, you could add a empty ítem (Text="" and Value=Guid.Empty, for example) and set SelectedValue=Guid.Empty if Eval("security_webpage_id") == null .

Cheers.

David Ortega.
0
David
Top achievements
Rank 1
answered on 13 Feb 2015, 04:49 PM
Thank you for the good ideas David. I have gotten past this point now because of you.
But I have a new problem as a result of this fix. I will post in new thread.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
davortsan
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or