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

RadComboBox in FormView

3 Answers 173 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 10 Mar 2011, 12:12 PM

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

3 Answers, 1 is accepted

Sort by
0
Helen
Telerik team
answered on 16 Mar 2011, 01:40 PM
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!
0
Andry
Top achievements
Rank 1
answered on 27 Sep 2011, 04:04 PM
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
0
Shinu
Top achievements
Rank 2
answered on 28 Sep 2011, 12:40 PM
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.
Tags
ComboBox
Asked by
Rahul
Top achievements
Rank 1
Answers by
Helen
Telerik team
Andry
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or