rendered paste body// aspx page
<asp:GridView
ID="gvCategories"
runat="server"
AutoGenerateColumns="False"
AutoGenerateDeleteButton="true"
AutoGenerateEditButton="true"
EnableViewState="False"
AllowSorting="true"
OnSorting="gvCategories_Sorting"
DataKeyNames="CategoryPkey"
>
<Columns>
<asp:BoundField HeaderText="ID" DataField="CategoryPkey" ReadOnly="True" SortExpression="CategoryPkey">
<ItemStyle Width="20px" />
</asp:BoundField>
<asp:BoundField HeaderText="Category" DataField="CategoryNameEN" SortExpression="CategoryNameEN">
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField HeaderText="Description" DataField="CategoryDescriptionEN" SortExpression="CategoryDescriptionEN">
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:BoundField HeaderText="IsSubcategory" DataField="IsSubcategory" SortExpression="IsSubcategory">
<ItemStyle Width="30px" />
</asp:BoundField>
<asp:CheckBoxField DataField="IsSubcategory" SortExpression="IsSubcategory" HeaderText="IsSubcategory" >
<ItemStyle Width="30px" />
</asp:CheckBoxField>
</Columns>
</asp:GridView>
// --------------------------------------------------------------
// cs page
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindControls();
}
}
protected void BindControls()
{
this.gvCategories.DataSource = DAL.cCategories.GetAllCategories();// GetAllCategoriesSqlCached();
this.gvCategories.DataBind();
}
protected void gvCategories_Sorting(object sender, GridViewSortEventArgs e)
{
if (e.SortExpression == "CategoryPkey")
{
this.lblGrid.Text = "You cant sort by ID";
}
else
{
this.lblGrid.Text = "Sorting by " + e.SortExpression.ToString() + " in " + e.SortDirection.ToString() + " order...";
}
}