Hi Mohal,
Please refer below sample to get DataTable when binding using SQLDataSource.
HTML
<asp:GridView runat="server" ID="gvCustomers" AutoGenerateColumns="false" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:CommandField ButtonType="Button" ShowEditButton="true" HeaderText="Button" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT CustomerId,Name,Country FROM Customers"></asp:SqlDataSource>
<br />
<asp:Button Text="Save" runat="server" OnClick="OnSave" />
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void OnSave(object sender, EventArgs e)
{
DataView dv = (DataView)SqlDataSource1.Select(new DataSourceSelectArguments());
DataTable dt = dv.ToTable();
}
VB.Net
Protected Sub OnSave(ByVal sender As Object, ByVal e As EventArgs)
Dim dv As DataView = CType(SqlDataSource1.[Select](New DataSourceSelectArguments()), DataView)
Dim dt As DataTable = dv.ToTable()
End Sub
Screenshot