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

Checkbox column in Filtering radgrid.

0 Answers 293 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gowtham
Top achievements
Rank 1
Gowtham asked on 14 Jun 2012, 03:03 AM
hi all,
 
I m using filtering radgrid.

I'm using 2008 version of telerik DLL which does not support "Filter Template". I want to develop a screen which is something like the one attached.

As you can see the attachment i want a button in place of filter text boxes and this is for two columns alone(Column Nominate and Column Approve). To achieve that i wrote a class which is below.

public class GenerateButton : GridCheckBoxColumn
    {
 
        //RadGrid will call this method when it initializes the controls inside the filtering item cells
        protected override void SetupFilterControls(TableCell cell)
        {
 
            base.SetupFilterControls(cell);
            cell.Controls.RemoveAt(0);
            Button b = new Button();
            b.ID = ("SelectDeselect"+ this.UniqueName);
            b.BackColor = System.Drawing.Color.White;
            b.Text = "Select/Deselect All";
            string s = b.ID;
                 
            //b.OnClientClick = "clickbutton('"+s+"')";
            if (s.Equals("SelectDeselectColumnNominate"))
            {
                b.OnClientClick = "ColumnNominateClickButton()";
            }
            else if(s.Equals("SelectDeselectColumnApprove"))
            {
                b.OnClientClick = "ColumnApproveClickButton()";
            }
            cell.Controls.AddAt(0, b);
            cell.Controls.RemoveAt(1);
 
        }
 
 
    }


For those two columns i used the below logic which is written in the PageLoad.
if (dataColumn.ColumnName == "ColumnNominate")
     {
            GenerateButton columnNominate = new GenerateButton();
             RadGrid1.MasterTableView.Columns.Add(columnNominate);
             columnNominate.DataField = dataColumn.ColumnName;
             columnNominate.SortAscImageUrl = @"Arrow Down.jpg";
             columnNominate.SortDescImageUrl = @"Arrow Up.jpg";
             columnNominate.HeaderText = dataColumn.ColumnName;
      }
       else if (dataColumn.ColumnName == "ColumnApprove")
        {
         GenerateButton columnApprove = new GenerateButton();
          this.RadGrid1.MasterTableView.Columns.Add(columnApprove);
           columnApprove.DataField = dataColumn.ColumnName;
           columnApprove.SortAscImageUrl = @"Arrow Down.jpg";
           columnApprove.SortDescImageUrl = @"Arrow Up.jpg";
           columnApprove.HeaderText = dataColumn.ColumnName;
         }

Item data bound logic is below where in i'm setting the properties of checkboxes.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                CheckBox chkbxNominate = (CheckBox)item["ColumnNominate"].Controls[0];
                chkbxNominate.ID = "ChkNominate";
                 
                chkbxNominate.Visible = true;
                chkbxNominate.Enabled = true;
              
 
                CheckBox chkbxApprove = (CheckBox)item["ColumnApprove"].Controls[0];
                chkbxApprove.ID = "ChkApprove";
                chkbxApprove.Visible = true;
                chkbxApprove.Enabled = true;
                
 
            }
          
        }

Now things are getting complicated for me.

The following tasks needs to be done
1. Persist the checkbox's checked status while i filter.
2. On clicking the SelectAll/DeselectAll button i need to select all checkboxes and deselect all checkboxes. I wrote this in javascript and is working fine
3. I need to identify the checked checkboxes in the (.cs) file so that i could pass in this value to the DB. Now where to write this logic? If i try to find the checkboxes in the "ColumnNominate" or "ColumnApprove" then the system is throwing an error saying "No controls are bound to that particular cell". Kind suggestion please on how to proceed further?

Also can you please suggest me some other better way to create two checkbox columns programatically?

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Gowtham
Top achievements
Rank 1
Share this question
or