sortcode for DataGrid control
protected void Sortdg_SortCommand(object source, DataGridSortCommandEventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection BindConnection = new SqlConnection("Data Source=AB2\\SQLEXPRESS;Initial Catalog=Tiger;Integrated Security=True");
SqlCommand comBindData = new SqlCommand("select * from stock", BindConnection);
comBindData.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(comBindData);
DataSet ds = new DataSet();
myAdapter.Fill(ds);
DataView dvSort = new DataView(ds.Tables[0]);
Sortdg.DataSource = dvSort;
Sortdg.DataBind();
dvSort.Sort = e.SortExpression;
}
}
This above code I am using to sort my datagrid but its not working out give me a solution with the same code or a different one.
Regards,
Rathi