Hi All,
I have one gridview and i want to take all the values in a datatable or dataview.
I tried like this
DataTable gridTable = (DataTable) dataGrid1.DataSource;
but gridTable is showing null, it should not show null because gridview has lot of records with 3 columns
Is there any way i can convert/store a gridview.Datasource records in a datatable or dataview?
Loading
Ajay GautamPosted Jul 28, 2010, 10:22 AM
Page_Load()
{
gvAssignedGroups.DataSource = dtAssignedGroups;
gvAssignedGroups.DataBind();
Session["dsAssignedGroup1"] = dtAssignedGroups;
}
protected void gsAU1GroupSort(object sender, GridViewSortEventArgs e)
{
GridView gvAvailableGroups = (GridView)gsAU1Groups.Controls[0].FindControl("gvAvailableGroups");
GridView gvAssignedGroups = (GridView)gsAU1Groups.Controls[0].FindControl("gvAssignedGroups");
DataTable dtAssignedGroupSort = (System.Data.DataTable)Session["dsAssignedGroup1"];
dtAssignedGroupSort.DefaultView.Sort = e.SortExpression;
if ((string)ViewState["sortField"] == e.SortExpression.ToString())
{
if ((string)ViewState["sortDirection"] == "ASC")
{
ViewState["sortDirection"] = "DESC";
}
else
{
ViewState["sortDirection"] = "ASC";
}
}
else
{
ViewState["sortField"] = e.SortExpression.ToString();
ViewState["sortDirection"] = "ASC";
}
gvAssignedGroups.DataSource = dtAssignedGroupSort;
gvAssignedGroups.DataBind();
}
Ajay GautamPosted Jul 26, 2010, 10:33 PM
Hiren SoniPosted Jul 25, 2010, 8:53 AM
here is an article,
which explains you step by step
http://www.codeproject.com/KB/aspnet/GridView_To_DataTable.aspx