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

How to check in JavaScript grid rowcount before exporting grid

1 Answer 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Igor Ashmetkov
Top achievements
Rank 1
Igor Ashmetkov asked on 12 Jun 2013, 05:17 PM
    Hello.
I`m using RadGrid populating data in OnNeedDataSource.
I want to check row count on client side before exporting and if row count is greater than 100000 (for examle) I want to show  Alert('Can`t exporf data, please specify another criteria')
How can I do this? What client event use? How to check row count on client side?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 13 Jun 2013, 05:54 AM
Hi,

I have tried an example,you may try if this helps,its done with the help of external button click.Just check this code.

ASPX:
<telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="true" DataSourceID="SqlDataSource2"
    AutoGenerateColumns="false">
    <MasterTableView CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn DataField="CustomerID" HeaderText="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CompanyName" HeaderText="CompanyName" UniqueName="CompanyName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Address" HeaderText="Address" UniqueName="Address">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ContactTitle" HeaderText="ContactTitle" UniqueName="ContactTitle">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>          
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Export TO PDF" OnClick="Button1_Click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    RadGrid2.MasterTableView.AllowPaging = false;
    RadGrid2.Rebind();
    int c = RadGrid2.MasterTableView.Items.Count;
    RadGrid2.MasterTableView.AllowPaging = true;
    RadGrid2.Rebind();
    Button1.Attributes.Add("onclick", "count('" + c + "');");
    if (c <= 20)
    {
        RadGrid2.MasterTableView.ExportToPdf();
    }      
}

JS:
function count(c)
 {
  alert("Total No.Of Records " + c);
  if (c > 20)
  {
    alert("Cant Export More than 20!");
  }
 }

Thanks,
Princy
Tags
Grid
Asked by
Igor Ashmetkov
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or