retrieve all checkbox ticked rows from radgrid

6 posts, 0 answers
  1. digish devassy
    digish devassy avatar
    18 posts
    Member since:
    Mar 2010

    Posted 28 Feb 2012 Link to this post

    I am able to check all the checkboxes. But When I tried to retrieve all the checked boxes, checked, I am able to get the checkboxes ticked only in the first page.
    other page value are not getting retrieved using the code:

    for (int i = 0; i < rdNew.Items.Count; i++)
    {
    CheckBox chkSelected = (CheckBox)rdNew.Items[i].FindControl("chkSelected");
    String Id = rdNew.Items[i]["id"].Text;

    if (chkSelected.Checked && chkSelected != null)
    {
    if (list.Count == 0)
    {
    list.Add(Id);
    }
    }
    }
    I am not getting the total list, of the users checked.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Feb 2012 Link to this post

    Hello,

    I cannot reproduce the issue at my end. Check the following help documentation.
    Persisting CheckBox control state in GridTemplateColumn on rebind.

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. digish devassy
    digish devassy avatar
    18 posts
    Member since:
    Mar 2010

    Posted 29 Feb 2012 Link to this post

    HI shinu,

    I respect your replies,

    I am in a hurry. All my requirement is, how to loop through all the checked checkboxes in radgrid and get the id associated with the checkboxed rows. I am not finding a solution. my client has bought your stuff. It is painful to see that, I get such non serious replies from telerik forum
    thanks,
  5. Solucky
    Solucky avatar
    1 posts
    Member since:
    Jan 2012

    Posted 29 Feb 2012 Link to this post

    Hi,

    i hope it will help

    //MakeAllowPaging false and collect all data
             radVenues
    .AllowPaging =
    false;
    radVenues.Rebind();


    List<
    int> CheckedItemlist = new List<int>();
                var Count=(from Item in radVenues.MasterTableView.Items.Cast<GridDataItem>()
                           where  ((CheckBox)Item.FindControl("chkLoop")).Checked=true
                           select AddItemIdinList(Item,CheckedItemlist)).Count();

    //MakeAllowPaging True
       radVenues.AllowPaging = true;
       radVenues.Rebind();

     
     public bool AddItemIdinList(GridDataItem Item, List<int> Itemlist)
            {
                int id=0;
                int.TryParse(Item.GetDataKeyValue("ID").ToString(), out id);
                Itemlist.Add(id);
                return true;
            }
    Regards,
    Bhavik Solucky
  6. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 29 Feb 2012 Link to this post

    Hello,

    <telerik:RadGrid ID="grdShipments" Skin="Office2007" runat="server" GridLines="None"
                AllowPaging="True" PageSize="2" AllowSorting="True" AutoGenerateColumns="False"
                ShowStatusBar="true" AllowFilteringByColumn="true" OnNeedDataSource="grdShipments_NeedDataSource">
                <MasterTableView CommandItemDisplay="Top" EnableNoRecordsTemplate="true" ShowHeader="true"
                    ShowHeadersWhenNoRecords="true">
                    <Columns>
                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                                <asp:CheckBox ID="chkI" runat="server" />
                            </ItemTemplate>
                            <HeaderTemplate>
                                 <asp:CheckBox ID="chkH" runat="server" AutoPostBack="true"
                oncheckedchanged="chkH_CheckedChanged" />
                            </HeaderTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="Shipper" HeaderText="Shipper" UniqueName="Shipper"
                            AllowFiltering="true">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ShipDate" HeaderText="ShipDate" UniqueName="ShipDate"
                            AllowFiltering="true">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    protected void grdShipments_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Shipper", typeof(string));
            dt.Columns.Add("ShipDate", typeof(DateTime));
            dt.Rows.Add("Shipper1", DateTime.Now.AddDays(1));
            dt.Rows.Add("Shipper2", DateTime.Now.AddDays(2));
            dt.Rows.Add("Shipper3", DateTime.Now.AddDays(3));
            dt.Rows.Add("Shipper1", DateTime.Now.AddDays(1));
            dt.Rows.Add("Shipper2", DateTime.Now.AddDays(2));
            dt.Rows.Add("Shipper3", DateTime.Now.AddDays(3));
     
            grdShipments.DataSource = dt;
        }
        protected void chkH_CheckedChanged(object sender, EventArgs e)
        {
     
            CheckBox chkH = sender as CheckBox;
     
            foreach (GridDataItem item in grdShipments.MasterTableView.Items)
            {
                CheckBox chkI = item.FindControl("chkI") as CheckBox;
                chkI.Checked = chkH.Checked;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            GridHeaderItem hItem = grdShipments.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
            if (hItem != null)
            {
                CheckBox chkH = hItem.FindControl("chkH") as CheckBox;
                if (chkH.Checked)
                {
                    grdShipments.AllowPaging = false;
                    grdShipments.Rebind();
     
                    string strTemp = grdShipments.Items.Count.ToString();
                    foreach (GridDataItem item in grdShipments.Items)
                    {
                        // Do your Logic Here
                    }
     
                    grdShipments.AllowPaging = true;
                    grdShipments.Rebind();
     
                    
                    foreach (GridDataItem item in grdShipments.MasterTableView.Items)
                    {
                        CheckBox chkI = item.FindControl("chkI") as CheckBox;
                        chkI.Checked = chkH.Checked;
                    }
     
                }
            }
        }

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  7. Jaya
    Jaya avatar
    81 posts
    Member since:
    Mar 2011

    Posted 20 Feb 2015 in reply to Jayesh Goyani Link to this post

    Hi
    Jayesh Goyani

    I have Telerik Radgrid following Fields 

    Name,Empno last field checkbox like this

     <telerik:GridTemplateColumn HeaderText="Status">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="ChkStatus" runat="server" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>    
    Here when i click save button i need check column wise data get the value in Telerik Radgrid how will do this








Back to Top
UI for ASP.NET Ajax is Ready for VS 2017