RadComboBox in FormView

4 posts, 0 answers
  1. Rahul
    Rahul avatar
    1 posts
    Member since:
    Mar 2011

    Posted 10 Mar 2011 Link to this post

    Hi,

    I am using RadComboBox in FormView and i am facing some issues. Well, its a simple data bind case involving Rad Combo Box; in which radcombobox is bound with values from a DataTable.
    The code is as follows and is called from the PageLoad() event of the page

     

     

     

    DataTable tb = FM.Get_tbl(); //Gets data from backend

     

     

    //Forms View
    FormsView1.DataSource = tb;

     

    FormsView1.DataBind();

    RadComboBox rad_No = (RadComboBox)FormsView1.FindControl("rad_No");

     

     

    rad_No.DataSource = tb;

     

    rad_No.DataTextField =

    "Column_Name";

     

     

    rad_No.DataValueField =

    "Column_Name";

     

     

     

     

     

     

    rad_No.DataBind();

    On running this code it displays "Column_Name" as the values/Text in RadComboBox instead of the real data(Data from backend of the mentioned column).

    I have used the same code mentioned below with success but with RadComboBox outside FormsView.
    RadComboBox rad_No = (RadComboBox)FormsView1.FindControl("rad_No");

     

     

    rad_No.DataSource = tb;

     

    rad_No.DataTextField =

     

    "Column_Name";

     

     

    rad_No.DataValueField =

     

    "Column_Name";

     

     

     

     

     

     

    rad_No.DataBind();

     

     

     

    Can anyone help me with this?

    Regards,
    Rahul Babbar

  2. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 16 Mar 2011 Link to this post

    Hello Rahul,

    Could you please send us a project which demonstrates the issue to examine it locally?

    Greetings,
    Helen
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Andry
    Andry avatar
    4 posts
    Member since:
    Sep 2011

    Posted 27 Sep 2011 Link to this post

    Hi,

    I think I have a similar problem.

    when I try to reference a RadComboBox from FormView, it returns null and can't be referenced.

    aspx sample:

    <asp:FormView ID="fvOrder" DataSourceID="ldsOrder" DataKeyNames="OrderID" DefaultMode="Edit" OnDataBound="FVOrderDataBound" runat="server">
      <EditItemTemplate>
        <telerik:RadComboBox ID="ddlCountry" runat="server" />
        <asp:Label ID="lblState" runat="server" />
      </EditItemTemplate>
    </asp:FormFiew>

    cs

    protected void FVOrderDataBound(object sender, EventArgs e)
    {
      RadComboBox rcb = fvOrder.FindControl("ddlCountry") as RadComboBox;
      Label lbl = fvOrder.FindControl("lblState") as Label;

      rcb.SelectedValue = "1";
      lbl.Text = "WA";
    }

    This actually returns an error. When "1" is being assigned to rcb.SelectedValue, it is pointed that rcb is null. It seems like rcb is not referenced correctly. The FindControl didn't work. Label works perfectly and have no problems.

    Could someone please assist me on this?

    Cheers,

    Andry
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Sep 2011 Link to this post

    Hello Andry,

    I have tried reproducing the issue at my end but no avail. Your code worked as expected when the FormView is directly available in the page. If it is inside any control access the FormView first and then the control.Here is the code which I tried.
    aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FormView.aspx.cs" Inherits="RadGrid_FormView" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="script" runat="server">
            </asp:ScriptManager>
            <asp:FormView ID="fvOrder" DataSourceID="SqlDataSource1" DataKeyNames="EmployeeID"
                DefaultMode="Edit" OnDataBound="FVOrderDataBound" runat="server">
                <EditItemTemplate>
                    <telerik:RadComboBox ID="ddlCountry" runat="server" />
                    <asp:Label ID="lblState" runat="server" />
                </EditItemTemplate>
            </asp:FormView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [HireDate], [Country], [ReportsTo] FROM [Employees]">
            </asp:SqlDataSource>
        </div>
        </form>
    </body>
    </html>

    Thanks,
    Shinu.
Back to Top