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

NestedViewTemplate with Dropdownlist SelectedValue does not exist?

1 Answer 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 03 Jul 2011, 05:27 AM
Hi all,
I have a Grid wich is using a NestedViewTemplate to display details when selected similar to the example here http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplatedeclarativerelations/defaultcs.aspx


Everything is working ok, except for one control.
I have a dropdown list that I use to display the preferred language in. When I select a record I get the error:

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

I found a document online that tells me:
...
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).

This problem can be fixed in the following ways:

  • preset the default value of the control(s) when binding to a grid item on the RadGrid.InitInsertCommandName command.

...

Here is the code I have in my NestedViewTemplate:
                                     <asp:DropDownList ID="cboLanguage" runat="server" DataSourceID="dsLanguage" DataTextField="Text"
                                            DataValueField="value" SelectedValue='<%# Bind("LanguageID") %>' AppendDataBoundItems="True"  >
                                            <asp:ListItem Value="-1">Please Select</asp:ListItem>
                                        </asp:DropDownList>
                                        <asp:ObjectDataSource ID="dsLanguage" runat="server" SelectMethod="FetchEntries"
                                            TypeName="BenemTech.SHSR_DonorMgmt.DAO.ListDAO">
                                            <SelectParameters>
                                                <asp:Parameter DefaultValue="Language" Name="GroupName" Type="String" />
                                            </SelectParameters>
                                        </asp:ObjectDataSource>

So the problem described makes a little sense, but I have no idea how to do what the document suggests.
I am using VS 2010 and simply can't find this InitInsertCommandName method or property or event

Can somebody please post simple code that would go in this event (once I find it) to make this work?

Thanks in advance.



I am willing to try this (not sure why it matters though) but

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Jul 2011, 08:52 AM
Hello Paul,

You can populate the DropDownList in ItemCommand event by checking for CommandName-"InitInsertCommandName". Here is the sample code that I tried which worked as expected. Hope this helps.

C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
        if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            e.Canceled = true;
            System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
            newValues["LanguageID"] = "";       
            e.Item.OwnerTableView.InsertItem(newValues);
        }
}

Thanks,
Princy.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or