<asp:GridView ID="gvDetails" runat="server"
AutoGenerateColumns="False" AllowPaging="true"
onsorting="gvDetails_Sorting" PageSize="6" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="EmployeeName" SortExpression="EmployeeName">
<ItemTemplate>
<asp:Label ID="lblFname" runat="server" Text='<%#Eval("EmployeeName")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" SortExpression="Mobile">
<ItemTemplate>
<asp:Label ID="lblLname" runat="server" Text='<%#Eval("Mobile")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BatchCode" SortExpression="BatchCode">
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%#Eval("BatchCode")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created" SortExpression="Created">
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%#Eval("Created")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
gvDetails.DataSource = BindGridView();
gvDetails.DataBind();
}
protected void gvDetails_Sorting(object sender, GridViewSortEventArgs e)
{
string sortingDirection = string.Empty;
if (sortProperty == SortDirection.Ascending)
{
sortProperty = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
sortProperty = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(BindGridView());
sortedView.Sort = e.SortExpression + " " + sortingDirection;
gvDetails.DataSource = sortedView;
gvDetails.DataBind();
}
private DataTable BindGridView()
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Employee Feedback Details"];
SPListItemCollection item = list.GetItems();
//foreach (SPListItem items in item) ;
//{
//}
DataTable dt = new DataTable();
dt = item.GetDataTable();
return dt;
//gvDetails.DataSource = dt;
//gvDetails.DataBind();
}
public SortDirection sortProperty
{
get
{
if (ViewState["SortingState"] == null)
{
ViewState["SortingState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["SortingState"];
}
set
{
ViewState["SortingState"] = value;
}
}
AutoGenerateColumns="False" AllowPaging="true"
onsorting="gvDetails_Sorting" PageSize="6" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="EmployeeName" SortExpression="EmployeeName">
<ItemTemplate>
<asp:Label ID="lblFname" runat="server" Text='<%#Eval("EmployeeName")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" SortExpression="Mobile">
<ItemTemplate>
<asp:Label ID="lblLname" runat="server" Text='<%#Eval("Mobile")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BatchCode" SortExpression="BatchCode">
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%#Eval("BatchCode")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created" SortExpression="Created">
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%#Eval("Created")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
gvDetails.DataSource = BindGridView();
gvDetails.DataBind();
}
protected void gvDetails_Sorting(object sender, GridViewSortEventArgs e)
{
string sortingDirection = string.Empty;
if (sortProperty == SortDirection.Ascending)
{
sortProperty = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
sortProperty = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(BindGridView());
sortedView.Sort = e.SortExpression + " " + sortingDirection;
gvDetails.DataSource = sortedView;
gvDetails.DataBind();
}
private DataTable BindGridView()
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Employee Feedback Details"];
SPListItemCollection item = list.GetItems();
//foreach (SPListItem items in item) ;
//{
//}
DataTable dt = new DataTable();
dt = item.GetDataTable();
return dt;
//gvDetails.DataSource = dt;
//gvDetails.DataBind();
}
public SortDirection sortProperty
{
get
{
if (ViewState["SortingState"] == null)
{
ViewState["SortingState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["SortingState"];
}
set
{
ViewState["SortingState"] = value;
}
}
No comments:
Post a Comment