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

Dropdownlist in FormTemplate still not working

4 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brendan Vogt
Top achievements
Rank 1
Brendan Vogt asked on 26 Aug 2008, 07:49 AM
Hi,

I am struggling with my dropdownlist in my FormTemplate.  When I click on the Insert link it populates the dropdownlist just fine.

<radcb:RadComboBox
   ID="rcbTitles"
   AppendDataBoundItems="true"
   DataSourceID="odsTitles"
   DataTextField="Description"
   DataValueField="TitleID"
   Skin="WindowsGray"
   SelectedValue='<%# Bind("Titles") %>'
   runat="server">
   <Items>
      <radcb:RadComboBoxItem Text="Select" Value="" />
   </Items>
</radcb:RadComboBox>


My ItemCommand looks like:

if (e.CommandName == RadGrid.InitInsertCommandName)
{
   e.Canceled = true;

   ListDictionary newValues = new ListDictionary();
   newValues["Titles"] = "";
   //Insert the item and rebind
   e.Item.OwnerTableView.InsertItem(newValues);
}


I am using a FormTemplate.  I am not understanding my error, I have been struggling for 2 days, is there no one on this forum that can help me?  When I click on the Insert link and click cancel I get the following error:

DataBinding: 'Telerik.WebControls.GridInsertionObject' does not contain a property with the name 'Titles'.

What am I doing wrong?  Please can some try and help me??

Thanks
Brendan

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 26 Aug 2008, 01:09 PM
Hi Brendan,

I tested your sample code in a project as close to the suggested as possible. I am not getting any errors under the described scenario. Please check if a data field named "Titles" exists in RadGrid's data source, and if it is present as a column in RadGrid.

Best wishes,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Brendan Vogt
Top achievements
Rank 1
answered on 26 Aug 2008, 01:47 PM
My grid is loaded like this:

private void LoadCommunication()
{
   int _ClientId = Int32.Parse(Request.QueryString["ClientId"]);
   List<Communication> communications = CommunicationManager.QueryCommunicationsByClientId(_ClientId);

   rgCommunications.DataSource = communications;
   rgCommunications.DataBind();
}

In each Communication class there is a reference to the Title class.  So if I need to access the the TitleID property, then it would be something like:

Communication.Title.TitleID

The object datasource in my .aspx file to load the titles looks like:

<asp:ObjectDataSource
   ID="odsTitles"
   TypeName="Nedbank.Excon.Lookup.TitleManager"
   SelectMethod="GetTitles"
   runat="server">
</asp:ObjectDataSource>


I know that my error is here:

SelectedValue='<%# Bind("Titles") %>'

..but I do not know how to fix it, or make it work.  There is no Titles property.  I'm assuming they are looking for the Title.TitleID?  This does not work in Bind("Title.TitleID").  I did read the sample applications.
0
Brendan Vogt
Top achievements
Rank 1
answered on 26 Aug 2008, 02:12 PM
Hi,

Can I please see the code that you used?

Thanks
Brendan
0
Veli
Telerik team
answered on 27 Aug 2008, 10:19 AM
Hello Brendan,

Please note that for complex data operations, RadGrid requires that it is bound to a data source either through a data source control (as of ASP.NET 2.0), or through the NeedDataSource event. Please consider this requirement.

As of the Titles property, indeed, due to some misconfigured object data relation, the Titles property might be either non-existent, or some sub-property of a parent object.

As for the sample project I tested on, here is the code:

<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
<div> 
    <telerik:RadGrid ID="RadGrid1" runat="server" Width="800px" Skin="Office2007" 
        AutoGenerateColumns="true" AutoGenerateEditColumn="true" DataSourceID="AccessDataSource1"
        <MasterTableView EditMode="EditForms" CommandItemDisplay="top"
            <EditFormSettings EditFormType="Template"
                <FormTemplate> 
                <div style="text-align:right; width:300px;"
                    ProductID:&nbsp<asp:TextBox ID="ProductIDTextBox" runat="server" Text='<%# Bind("ProductID") %>' Width="200px"></asp:TextBox><br /> 
                    ProductName:&nbsp<asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>' Width="200px"></asp:TextBox><br /> 
                    UnitPrice:&nbsp<asp:TextBox ID="UnitPriceTextBox" runat="server" Text='<%# Bind("UnitPrice") %>' Width="200px"></asp:TextBox><br /> 
                    Category:&nbsp 
                    <telerik:RadComboBox ID="CategoryCombo" runat="server" DataSourceID="AccessDataSource2" 
                        DataTextField="CategoryName" DataValueField="CategoryID" AppendDataBoundItems="true" 
                        Text='<%# Bind("CategoryID") %>' Width="202px" Skin="Office2007"
                        <Items> 
                            <telerik:RadComboBoxItem Text="Select" Value="" /> 
                        </Items> 
                    </telerik:RadComboBox> 
                </div> 
                <br /> &nbsp 
                <asp:LinkButton ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                </asp:LinkButton>&nbsp; 
                <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"
                </asp:LinkButton> 
                </FormTemplate> 
            </EditFormSettings> 
        </MasterTableView> 
    </telerik:RadGrid> 
</div> 
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Nwind.mdb" 
SelectCommand="SELECT TOP 10 [ProductID], [ProductName], [UnitPrice], [CategoryID] FROM [Alphabetical List of Products]"
</asp:AccessDataSource> 
 
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/Nwind.mdb" 
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"
</asp:AccessDataSource> 
</form> 

And the code-behind:

protected void Page_Load(object sender, EventArgs e) 
    RadGrid1.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(RadGrid1_ItemCommand); 
 
void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.InitInsertCommandName) 
    { 
        e.Canceled = true
 
        System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary(); 
        newValues["CategoryID"] = ""
        //Insert the item and rebind 
        e.Item.OwnerTableView.InsertItem(newValues); 
    } 


Sincerely yours,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Brendan Vogt
Top achievements
Rank 1
Answers by
Veli
Telerik team
Brendan Vogt
Top achievements
Rank 1
Share this question
or