SelectedValue problem

2 posts, 0 answers
  1. Bader
    Bader avatar
    215 posts
    Member since:
    Aug 2008

    Posted 19 Jan 2011 Link to this post

    Hello,

    I have a problem in displaying the returned value from Database in the radcombobox. In other words if I put the following code in the RadGrid EditForm then I can't submit the changes (If I click update I recieve an error):
    <telerik:RadComboBox ID="CstmrIDRadComboBox" OffsetX="-20" Skin="Vista" 
                                runat="server" Width="250px" Height="150px" AutoPostBack="false"
                                EnableLoadOnDemand="true" ShowMoreResultsBox="true" DataValueField="CstmrID" DataTextField="CstmrName"
                                EnableVirtualScrolling="true"  SelectedValue='<%# DataBinder.Eval( Container, "DataItem.CstmrID" ) %>' >
                                <WebServiceSettings Method="GetCstmrsNames" Path="AddBsns.aspx" />

    and
    private const int ItemsPerRequest = 10;
    [WebMethod]
    public static RadComboBoxData GetCstmrsNames(RadComboBoxContext context)
    {
        DataTable data = GetData(context.Text);
        RadComboBoxData comboData = new RadComboBoxData();
        int itemOffset = context.NumberOfItems;
        int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
        comboData.EndOfItems = endOffset == data.Rows.Count;
        List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(endOffset - itemOffset);
        for (int i = itemOffset; i < endOffset; i++)
        {
            RadComboBoxItemData itemData = new RadComboBoxItemData();
            itemData.Text = data.Rows[i]["CstmrName"].ToString();
            itemData.Value = data.Rows[i]["CstmrID"].ToString();
            result.Add(itemData);
        }
        comboData.Message = GetStatusMessage(endOffset, data.Rows.Count);
        comboData.Items = result.ToArray();
        return comboData;
    }
    private static DataTable GetData(string text)
    {
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from Customers WHERE CstmrName LIKE @text + '%'",
            ConfigurationManager.ConnectionStrings["MapConnectionString"].ConnectionString);
        adapter.SelectCommand.Parameters.AddWithValue("@text", text);
        DataTable data = new DataTable();
        adapter.Fill(data);
        return data;
    }
    private static string GetStatusMessage(int offset, int total)
    {
        if (total <= 0)
            return "No matches";
        return String.Format("{0} <b>1</b>-<b>{1}</b> {2} <b>{3}</b>", "Customers", offset, "Of", total);
    }

    Please, can you explain to me what is the problem and how can I fix it.
    It is appreciated to send me the modified code.

    Regards,
    Bader
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 20 Jan 2011 Link to this post

    Hi Bader,

    Please take a look at the  “Load On Demand RadComboBox inside an EditItemTemplate of RadGrid“ Code Library - the approach how to implement RadComboBox with Load On Demand within a RadGrid is described there.
    Additionally there is a sample project that you can download and test.

    Regards,
    Kalina
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top