New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

NeedDataSource Event

Fired when RadGrid needs a data source for rebinding.

Event Parameters

  • (object) sender

    • The control that fires the event
  • (GridNeedDataSourceEventArgs) e

    • Event arguments

      • (boolean) e.IsFromDetailTable

        Returns true if the event is fired for the DetailTable.

      • (GridRebindReason) e.RebindReason

        Gets a value specifying why the event was fired.

      • (int) e.RowsCount

        Gets a value specifying the number of rows that should be extracted from the data source when virtualization and custom paging are enabled.

      • (int) e.StartRowIndex

        Gets a value specifying the index of the first row in the data source that should be extracted when virtualization and custom paging are enabled.

Attaching the event

In the Markup

ASP.NET
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
</telerik:RadGrid>

In the Code behind

C#
protected void Page_Init(object sender, EventArgs e)
{
    RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
}

The event handler

C#
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    bool isFromDetailTable = e.IsFromDetailTable;
    GridRebindReason rebindReason= e.RebindReason;
    int rowsCount = e.RowsCount;
    int startRowIndex = e.StartRowIndex;
}

See Also