Get The ,How many row are select In rad grid view ...and RowIndex.

4 posts, 1 answers
  1. Sairam
    Sairam avatar
    56 posts
    Member since:
    May 2013

    Posted 05 Jun 2013 Link to this post

    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
                AutoGenerateColumns="false" onitemcommand="RadGrid1_ItemCommand">
                <MasterTableView AutoGenerateColumns="false">
                    <Columns>
                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server"   />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="employeenaem" HeaderText="EmployeeName">
                            <ItemTemplate>
                                <%#Eval("Employeename") %>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="employeeDesgination" HeaderText="EmployeeDesignation">
                            <ItemTemplate>
                                <%#Eval("EmployeeDesignation")%>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="Salary" HeaderText="salary">
                            <ItemTemplate>
                                <%#Eval("EmployeeSalary") %>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
            <telerik:RadButton ID="RadButton1" runat="server" Text="Print"
            onclick="RadButton1_Click">
            </telerik:RadButton>
      .aspx.cs 

      protected void RadButton1_Click(object sender, EventArgs e)
        {
            PrintDocument pd = new PrintDocument();
            foreach (GridDataItem item1 in RadGrid1.SelectedItems)
            {  
                CheckBox ChkedList = (CheckBox)item1.FindControl("CheckBox1");

               
            }
        }

    In the above code, I have check box in grid-template....column...when user  selected check box ...i want to know "row index" as well as ....How many rows are selected based on check box checked by user .
    I am used   Radgrid1.selectedItems....it's not working,  i am selected ......check-box and then click on  "Print" button ...not getting selected items count...

    but it's working other project fine.....Where I am done wrong....what is the  reason....any better solution to get the items.....
    and Row indexes of selected items....
    replay me.....

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Jun 2013 Link to this post

    Hi,

    Please try the following code snippet.

    ASPX:
    <telerik:GridTemplateColumn>
     <ItemTemplate>
             <asp:CheckBox ID="CheckBox1" runat="server" />
     </ItemTemplate>
    </telerik:GridTemplateColumn>
    ..............................................................................................
    <asp:Button ID="Button1" runat="server" Text="Count" OnClick="Button1_Click"  />

    C#:
    Set int count=0;
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
            if (chk.Checked)
            {
                string value = item["OrderID"].Text;// access the cell value using ColumnUniqueName
                count++;
            }
        }
        Response.Write(count);
    }

    Thanks
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sairam
    Sairam avatar
    56 posts
    Member since:
    May 2013

    Posted 06 Jun 2013 Link to this post

    Thanks,Princy and also I need ,The Row Index of currently....checked  check box Row.......
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jun 2013 Link to this post

    Hi,

    I have edited the above code as shown below.

    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
    {
        CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
        if (chk.Checked)
        {
            int index = item.ItemIndex;//access the selected checked checkbox rows
            Response.Write("<script language='javascript'>alert('Index :" + index + "');</script>");
            string value = item["OrderID"].Text;// access the cell value using ColumnUniqueName
            count++;
        }
    }
    Response.Write(count);
    }

    Thanks
    Princy
Back to Top