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

Unable to select checkbox of RadListBox in RadGrid

5 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sunil
Top achievements
Rank 1
sunil asked on 25 Nov 2010, 10:41 AM
I am creating a RadGrid programmatically. It has 2 template columns as well.
When we click Edit button for a row then, one template column has to be changed to a dropdown and other column should be changed to RadListbox of checkboxes.

Also, the ItemTemplate value should be used to select the appropriate checkboxes ni the RadListBox.

I have written the code to select the ListBoxItems of RadListBox, but it doesn't work. Can some help.

The code I have written is of this way:-


In RadGrid's Item Data Bound event:-

GridDataItem gridDataItem = e.Item as GridDataItem;
            DataRowView dvRow = gridDataItem.DataItem as DataRowView;
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     {
         GridDataItem gridDataItem = e.Item as GridDataItem;
         DataRowView dvRow = gridDataItem.DataItem as DataRowView;
 
         RadComboBox cmbPositionID = gridDataItem.FindControl("comboPositionID") as RadComboBox;
 
         cmbPositionID.SelectedValue = dvRow["PositionID"].ToString();
 
         RadListBox listBox = gridDataItem.FindControl("comboLanguageID") as RadListBox;
 
         string value = dvRow["LanguageID"].ToString();
 
         string[] values = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (string val in values)
         {
             RadListBoxItem item = listBox.FindItemByText(val);
             if (item != null)
                 item.Selected = true;
         }
 
       
     }




lic partial class Default : System.Web.UI.Page
{
    DataTable _userDT = new DataTable();
    DataTable _positionDT = new DataTable();
    DataTable _languageDT = new DataTable();

    RadGrid RadGrid1 = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadGrid1.DataBind(); 
    }

public partial class Default : System.Web.UI.Page
{
    DataTable _userDT = new DataTable();
    DataTable _positionDT = new DataTable();
    DataTable _languageDT = new DataTable();

    RadGrid RadGrid1 = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadGrid1.DataBind();
        }
    }

public partial class Default : System.Web.UI.Page
{
    DataTable _userDT = new DataTable();
    DataTable _positionDT = new DataTable();
    DataTable _languageDT = new DataTable();

  sdfasdfsadf  RadGrid RadGrid1 = null;
public partial class Default : System.Web.UI.Page
{
    DataTable _userDT = new DataTable();
    DataTable _positionDT = new DataTable();
    DataTable _languageDT = new DataTable();

    RadGrid RadGrid1 = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadGrid1.DataBind();
        }
    }
public partial class Default : System.Web.UI.Page
{
    DataTable _userDT = new DataTable();
    DataTable _positionDT = new DataTable();
asdfasdfdsafsa
    RadGrid RadGrid1 = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
  asdf          RadGrid1.DataBind();
        }
    }
    {
        if (!IsPostBack)
        {
 sadfRadGrid1.DataBind();
        }
sdaf

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Nov 2010, 12:05 PM
Hello Sunil,

You can select RadListBox item by setting Checked property of RadListBoxItem as true.

C#:
foreach (string val in values)
  {
      RadListBoxItem item = listBox.FindItemByText(val);
      if (item != null)
         item.Checked = true;
  }

Thanks,
Princy.
0
sunil
Top achievements
Rank 1
answered on 25 Nov 2010, 12:28 PM
I tried using Checked property as well..but of no use.
0
Iana Tsolova
Telerik team
answered on 29 Nov 2010, 04:49 PM
Hi sunil,

Can you confirm that the code in the ItemDataBound event handler is executed as expected?

Other than this, if the Checked property of an item is set to true, this should check the default CheckBox of the RadListBox item. If you are using ItemTemplate for the RadListBox items with custom CheckBox controls, then you need to find the particular checkbox and set its Checked property.

Regards,
Iana
the Telerik team
Browse the vast support resources we have to jumpstart 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.
0
sunil
Top achievements
Rank 1
answered on 29 Nov 2010, 05:04 PM
Yes the code executes properly and I am not using any custom check box control. You can look at my code in my initial post
0
Iana Tsolova
Telerik team
answered on 03 Dec 2010, 11:07 AM
Hello sunil,

I used the already suggested approach in the attached sample and it works as expected in my side. Try it on your end and let me know how it goes and if I missed something from your logic out.

Kind regards,
Iana
the Telerik team
Browse the vast support resources we have to jumpstart 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.
Tags
Grid
Asked by
sunil
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
sunil
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or