Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2010, 04:23 PM
sid sid is offline
Registered User
 
Join Date: Apr 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default filter in asp gridview

need to have filter on asp gridview which has bound fields as columns to display.

plz feel free to send the .aspx & code behind for the same.

its urgent
 
Old April 24th, 2010, 03:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

"Send me the codez, its urgent" messages typically result in zero answers. In this case you're really lucky as you can find a detailed answer to your question here: http://www.catb.org/~esr/faqs/smart-questions.html

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 25th, 2010, 02:07 AM
sid sid is offline
Registered User
 
Join Date: Apr 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default design & code behind for gridview filter

atchkstatus.aspx:
<%@ Page Language="C#" MasterPageFile="~/masterpage/atmaster.master" AutoEventWireup="true"
CodeBehind="atchkstatus.aspx.cs" Inherits="AbsenceTrackingSystem.atforms.atchkstatu s"
Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentAbsenceTracking" runat="server">
<asp:UpdatePanel ID="ajaxUpAtHome" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table class="myenttable">
<tr class="trStyles">
<td class="headerTdStyle">
My Employee Entitlement(s)
</td>
</tr>
<tr>
<td>
<asp:GridView ID="grdChkStatus" runat="server" AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="false" CssClass="mGrid" GridLines="None" OnPageIndexChanging="grdChkStatus_PageIndexChangin g"
OnRowCommand="grdChkStatus_RowCommand" OnSorting="grdChkStatus_Sorting" PagerStyle-CssClass="pgr"
PageSize="10" Width="100%">
<PagerStyle CssClass="pgr" />
<PagerSettings FirstPageText="First" LastPageText="Last" Mode="NextPreviousFirstLast"
NextPageText="Next" Position="Bottom" PreviousPageText="Prev" />
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<HeaderTemplate>
Status
<asp:DropDownList ID="ddlStatus" runat="server" AutoPostBack="true" DataSource="<%# GetStatusNames() %>"
DataTextField="Status" DataValueField="Status" OnPreRender="SetValue" OnSelectedIndexChanged="FilterDropDown_IndexChange d" />
<asp:ListItem Selected="True" Text="Select" Value="0" Enabled="true">
</asp:ListItem>
<asp:ListItem Text="All" Value="All">
</asp:ListItem>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AbsenceRequestID" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" HeaderStyle-ForeColor="#494949" HeaderText="ID"
ItemStyle-HorizontalAlign="Center" SortExpression="AbsenceRequestID" />
<asp:BoundField DataField="EmployeeName" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" HeaderStyle-ForeColor="#494949" HeaderText="Employee Name"
ItemStyle-HorizontalAlign="Center" SortExpression="EmployeeName" />
<asp:TemplateField HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="true" HeaderStyle-ForeColor="#494949" HeaderText="VIEW ABSENCE REQUEST">
<ItemTemplate>
<asp:LinkButton ID="lnkViewAbReq" runat="server" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
CommandName="ViewAbsenceRequest" CssClass="link" Text="View Absence Request"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<asp:Panel ID="pnlViewAbsence" runat="server" Visible="false">
<table class="myenttable">
<tr class="trStyles">
<td class="headerTdStyle">
Entitlement -
<asp:Label ID="lblViewAbsence" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="grdViewAbsence" runat="server" AutoGenerateColumns="false" GridLines="None"
AllowPaging="true" AllowSorting="true" OnSorting="grdViewAbsence_Sorting" CssClass="mGrid"
PagerStyle-CssClass="pgr" Width="101%" OnPageIndexChanging="grdViewAbsence_PageIndexChang ing"
PageSize="10">
<PagerStyle CssClass="pgr"></PagerStyle>
<PagerSettings Position="Bottom" Mode="NextPreviousFirstLast" FirstPageText="First"
LastPageText="Last" NextPageText="Next" PreviousPageText="Prev" />
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" HeaderStyle-ForeColor="#494949"
HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif" HeaderStyle-Font-Underline="false"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="AbsenceRequestID" HeaderText="ID" SortExpression="AbsenceRequestID"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="EmployeeName" HeaderText="Employee Name" SortExpression="EmployeeName"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="StartDate" HeaderText="Start Date" SortExpression="StartDate"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="EndDate" HeaderText="End Date" SortExpression="EndDate"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="NumberOfWorkingDays" HeaderText="Days" SortExpression="NumberOfWorkingDays"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="AbsenceType" HeaderText="Absence Type" SortExpression="AbsenceType"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

atchkstatus.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Garden.CookieAdmin;
using AbsenceTrackingService;

namespace AbsenceTrackingSystem.atforms
{
public partial class atchkstatus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetStatusNames();

ATService objClient = new ATService();
string errorMsg = string.Empty;
String strEmpSID = CookieManager.Read("strEmpSID");
DataSet dsStatus = objClient.GetAbsenceRequestModByEmpSID(strEmpSID, ref errorMsg);

if (dsStatus != null)
{
if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
grdChkStatus.DataSource = dsStatus.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatus.Tables[0];
}
else
{
ShowAlert("No records found!");
grdChkStatus.Visible = false;

}
}
}
}
}

protected void grdChkStatus_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
grdChkStatus.PageIndex = e.NewPageIndex;
grdChkStatus.DataSource = (DataTable)ViewState["DataSource"];
grdChkStatus.DataBind();
}
catch (Exception ex)
{

}
}

private string GetSortDirection(string column)
{

// By default, set the sort direction to ascending.
string sortDirection = "ASC";

// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;

if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}

// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;

return sortDirection;
}

protected void grdChkStatus_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = ViewState["DataSource"] as DataTable;

if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
grdChkStatus.DataSource = ViewState["DataSource"];
grdChkStatus.DataBind();
}
}

protected void grdChkStatus_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ViewAbsenceRequest")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvcurrentrow = grdChkStatus.Rows[index];
string strStatus = gvcurrentrow.Cells[0].Text.ToString();
string strAbReqID = gvcurrentrow.Cells[1].Text.ToString();
string strEname = gvcurrentrow.Cells[2].Text.ToString();
pnlViewAbsence.Visible = true;
lblViewAbsence.Text = strEname;
string errorMsg = string.Empty;
ATService objClientEmp = new ATService();
DataSet dsEmpAbs = null;
String strEmpSID = CookieManager.Read("strEmpSID");
dsEmpAbs = objClientEmp.GetAbsenceRequestModByEmpSID(strEmpSI D, ref errorMsg);
if (dsEmpAbs != null)
{
if (dsEmpAbs.Tables.Count > 0)
{
if (dsEmpAbs.Tables[0].Rows.Count > 0)
{

grdViewAbsence.DataSource = dsEmpAbs.Tables[0];
grdViewAbsence.DataBind();
ViewState["ViewDataSource"] = dsEmpAbs.Tables[0];
lblViewAbsence.Visible = false;
}
else
{
pnlViewAbsence.Visible = false;
lblViewAbsence.Visible = true;
lblViewAbsence.Text = "There is no Absence Request ID";
}
}
}
}



}

protected void grdViewAbsence_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
grdViewAbsence.PageIndex = e.NewPageIndex;
grdViewAbsence.DataSource = (DataTable)ViewState["ViewDataSource"];
grdViewAbsence.DataBind();
}
catch (Exception ex)
{

}
}

protected void grdViewAbsence_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = ViewState["ViewDataSource"] as DataTable;

if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
grdViewAbsence.DataSource = ViewState["ViewDataSource"];
grdViewAbsence.DataBind();
}
}

public DataSet GetStatusNames()
{


string errorMsg = string.Empty;
ATService objClient = new ATService();

//DataSet dsMgrAltMgrNAme = objClient.GetEmployeeProfileByMgrAltMgrName("U5663 06", ref errorMsg);
String strEmpSID = CookieManager.Read("strEmpSID");
DataSet dsStatus = objClient.GetAllEmployeeStatus(strEmpSID, ref errorMsg);
if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
DataRow orow = dsStatus.Tables[0].NewRow();
orow["Status"] = "All";
orow["EMPSID"] = "0";
dsStatus.Tables[0].Rows.InsertAt(orow, 0);
//lblAbsenceRequestBy.Text = "Status Type - " + dsStatus.Tables[0].Rows[0][12].ToString();
ddlStatus.DataSource = dsStatus.Tables[0];
//GridViewByStatus.DataSource = dsStatus.Tables[0];
//GridViewByStatus.DataBind();
//strEmpSID = dsMgrAltMgrNAme.Tables[0].Rows[0][0].ToString();

ddlStatus.DataTextField = "Status";
ddlStatus.DataValueField = "Status";
ddlStatus.DataBind();
//ViewState["DataSource"] = dsStatus.Tables[0];
return dsStatus;
}
}
return dsStatus;



}

public DataSet GetStatusDescriptions()
{
ATService objClient = new ATService();
string errorMsg = string.Empty;
String strEmpSID = CookieManager.Read("strEmpSID");
DataSet dsStatDesc = objClient.GetAbsenceRequestModByEmpSID(strEmpSID, ref errorMsg);

if (dsStatDesc != null)
{
if (dsStatDesc.Tables.Count > 0)
{
if (dsStatDesc.Tables[0].Rows.Count > 0)
{
grdChkStatus.DataSource = dsStatDesc.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatDesc.Tables[0];
return dsStatDesc;
}
else
{
ShowAlert("No records found!");
grdChkStatus.Visible = false;
}
}
}




return dsStatDesc;

}



protected void FilterDropDown_IndexChanged(object sender, EventArgs e)
{
string temp = ddlStatus.SelectedValue.ToString();


if (ddlStatus.SelectedValue == "0")
{

pnlViewAbsence.Visible = false;

grdChkStatus.Visible = true;
grdViewAbsence.Visible = false;


string errorMsg = string.Empty;
ATService objClient = new ATService();
String strEmpSID = CookieManager.Read("strEmpSID");
DataSet dsStatus = objClient.GetAbsenceRequestModByEmpSID(strEmpSID, ref errorMsg);

if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
//AbsenceRequest objAbsReq = new AbsenceRequest();
//objAbsReq.StartDate = ConvertDatetoLocaleFormat(objAbsReq.StartDate);
//objAbsReq.EndDate = ConvertDatetoLocaleFormat(objAbsReq.EndDate);
//lblReportType.Text = "Status Type - All";// +dsStatus.Tables[0].Rows[0][12].ToString();
grdChkStatus.DataSource = dsStatus.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatus.Tables[0];
}
else
{
ShowAlert("No records found!");
}
}


}

else if (ddlStatus.SelectedValue == temp)
{
string strempid = ddlStatus.SelectedValue.ToString();

pnlViewAbsence.Visible = false;

grdChkStatus.Visible = true;
grdViewAbsence.Visible = false;

string errorMsg = string.Empty;
ATService objClient = new ATService();
String strEmpSID = CookieManager.Read("strEmpSID");
//DataSet dsStatus = objClient.GetAbsReqStatusModByEmpSID("U394231", "Submit", ref errorMsg);
DataSet dsStatus = objClient.GetAbsReqStatusModByEmpSID(strEmpSID, "Submit", ref errorMsg);

if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
//AbsenceRequest objAbsReq = new AbsenceRequest();
//objAbsReq.StartDate = ConvertDatetoLocaleFormat(objAbsReq.StartDate);
//objAbsReq.EndDate = ConvertDatetoLocaleFormat(objAbsReq.EndDate);
//lblReportType.Text = "Status Type - " + dsStatus.Tables[0].Rows[0][12].ToString();
//dsStatus.Tables[0].Columns[].ColumnName.Remove;
grdChkStatus.DataSource = dsStatus.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatus.Tables[0];
}
else
{
ShowAlert("No records found!");
}
}

}
}

#region custom method for alert popups

protected void ShowAlert(string Message)
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "MyAlert", "alert('" + Message + "');", true);
}
#endregion custom method for alert popups


}
}
Above is the design & code behind.I need to have filter set on Status column which is the 1st column while displaying grid.

The second grid will be displayed on click of link button "ViewAbsenceRequest".

On page load 1st grid(grdChkStatus) needs to be loaded with All as default selection from dropdown.Now once the user chooses specific status the grid needs to display that record with that status value.

Plz modify the design & code behind for the same & send it across
 
Old April 28th, 2010, 04:09 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Plz modify the design & code behind for the same & send it across
Yes, sir. Anything else sir? Would tomorrow end of the day suit you sir?

You must have lost it, somewhere.....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 29th, 2010, 03:18 PM
sid sid is offline
Registered User
 
Join Date: Apr 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default gridview filter based on dropdown

Hi Imar,

I followed this blog,while doing the design & development for filtering in gridview.

In My gridview, I need to filter the records on Status which is a dropdownlist as the 1st column in the grid.For populating the dropdown,I have written method named GetStatusNames() which returns dataset with values(Submit,Approve,Reject & Cancel).There is also a method named GetStatusDescriptions() which returns a dataset with all values specific to Status.

Which method of the above 2 should I use in grdChkStatus_RowDataBound event of the grid as a datasource.

There is also a method named GetStatusView() which returns a dataview object.

I am following this blog:http://www.aspdotnetcodes.com/Asp.Ne...ew_Filter.aspx

Below is the .aspx & code behind for the work which I have done.

.aspx follows:

<%@ Page Language="C#" MasterPageFile="~/masterpage/atmaster.master" AutoEventWireup="true"
CodeBehind="atckst.aspx.cs" Inherits="AbsenceTrackingSystem.atforms.atckst" Title="Check My Request" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentAbsenceTracking" runat="server">
<asp:UpdatePanel ID="ajaxUpAtHome" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table class="myenttable">
<tr class="trStyles">
<td class="headerTdStyle">
Check My Request
<asp:GridView ID="grdChkStatus" runat="server" AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="false" CssClass="mGrid" GridLines="None" OnPageIndexChanging="grdChkStatus_PageIndexChangin g"
OnRowCommand="grdChkStatus_RowCommand" OnRowDataBound="grdChkStatus_RowDataBound"
OnSorting="grdChkStatus_Sorting" PagerStyle-CssClass="pgr" PageSize="10" Width="100%">
<PagerStyle CssClass="pgr" />
<PagerSettings FirstPageText="First" LastPageText="Last" Mode="NextPreviousFirstLast"
NextPageText="Next" Position="Bottom" PreviousPageText="Prev" />
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<HeaderTemplate>
Status
<asp:DropDownList ID="ddlStatus" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlStatus_IndexChanged">
<asp:ListItem Selected="True" Text="Select" Value="0" Enabled="true"></asp:ListItem>
<asp:ListItem Text="All" Value="ALL"></asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<%--<asp:Label ID="lblStatus" runat="server" CommandArgument='<%#Eval("Status") %>' Text='<%# Bind("Status") %>'></asp:Label>--%>
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AbsenceRequestID" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" HeaderStyle-ForeColor="#494949" HeaderText="ID"
ItemStyle-HorizontalAlign="Center" SortExpression="AbsenceRequestID" />
<asp:BoundField DataField="EmployeeName" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" HeaderStyle-ForeColor="#494949" HeaderText="Employee Name"
ItemStyle-HorizontalAlign="Center" SortExpression="EmployeeName" />
<asp:TemplateField HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="true" HeaderStyle-ForeColor="#494949" HeaderText="VIEW ABSENCE REQUEST">
<ItemTemplate>
<asp:LinkButton ID="lnkViewAbReq" runat="server" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
CommandName="ViewAbsenceRequest" CssClass="link" Text="View Absence Request"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
</table>
<asp:Panel ID="pnlViewAbsence" runat="server" Visible="false">
<table class="myenttable">
<tr class="trStyles">
<td class="headerTdStyle">
Absence Request -
<asp:Label ID="lblViewAbsence" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="grdViewAbsence" runat="server" AutoGenerateColumns="false" GridLines="None"
AllowPaging="true" AllowSorting="true" OnSorting="grdViewAbsence_Sorting" CssClass="mGrid"
PagerStyle-CssClass="pgr" Width="101%" OnPageIndexChanging="grdViewAbsence_PageIndexChang ing"
PageSize="10">
<PagerStyle CssClass="pgr"></PagerStyle>
<PagerSettings Position="Bottom" Mode="NextPreviousFirstLast" FirstPageText="First"
LastPageText="Last" NextPageText="Next" PreviousPageText="Prev" />
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" HeaderStyle-ForeColor="#494949"
HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif" HeaderStyle-Font-Underline="false"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="AbsenceRequestID" HeaderText="ID" SortExpression="AbsenceRequestID"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="EmployeeName" HeaderText="Employee Name" SortExpression="EmployeeName"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="StartDate" HeaderText="Start Date" SortExpression="StartDate"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="EndDate" HeaderText="End Date" SortExpression="EndDate"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="NumberOfWorkingDays" HeaderText="Days" SortExpression="NumberOfWorkingDays"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="AbsenceType" HeaderText="Absence Type" SortExpression="AbsenceType"
HeaderStyle-ForeColor="#494949" HeaderStyle-Font-Names="Verdana, Arial, Helvetica, sans-serif"
HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>


code-behind follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Configuration;
using System.Text;
using System.IO;
using System.Data.OracleClient;
using AbsenceTrackingService;
using DAL;
using System.Globalization;
using System.Threading;
using Garden.CookieAdmin;
using ATSession;

namespace AbsenceTrackingSystem.atforms
{
public partial class atckst : System.Web.UI.Page
{
public string Status = string.Empty;
string userRole = string.Empty;

public static readonly string Employee = "Employee";
public static readonly string Manager = "Manager";
public static readonly string LocalAdmin = "LocalAdmin";
public static readonly string GlobalAdmin = "GlobalAdmin";


protected void Page_Load(object sender, EventArgs e)
{
string userRole = SessionHandler.AbsenceTrackingRole;

if (!Page.IsPostBack)
{
grdViewAbsence.Visible = false;
//GetStatusNames();
//if (userRole == Employee || userRole == Manager || userRole == GlobalAdmin)
//{
//BindGridView();

ATService objClient = new ATService();
string errorMsg = string.Empty;
String strEmpSID = CookieManager.Read("strEmpSID");
DataSet dsStatus = objClient.GetAbChkReqByEmpSID(strEmpSID, ref errorMsg);

if (dsStatus != null)
{
if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
grdChkStatus.DataSource = dsStatus.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatus.Tables[0];
}
else
{
ShowAlert("No records found!");
grdChkStatus.Visible = false;

}
}
}
//}
//else
//{
// BindGridView();
//}
}
}

protected void grdChkStatus_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
grdChkStatus.PageIndex = e.NewPageIndex;
grdChkStatus.DataSource = (DataTable)ViewState["DataSource"];
grdChkStatus.DataBind();
}
catch (Exception ex)
{

}
}

private string GetSortDirection(string column)
{

// By default, set the sort direction to ascending.
string sortDirection = "ASC";

// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;

if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}

// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;

return sortDirection;
}

protected void grdChkStatus_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = ViewState["DataSource"] as DataTable;

if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
grdChkStatus.DataSource = ViewState["DataSource"];
grdChkStatus.DataBind();
}
}

protected void grdChkStatus_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ViewAbsenceRequest")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvcurrentrow = grdChkStatus.Rows[index];
string strStatus = gvcurrentrow.Cells[0].Text.ToString();
string strAbReqID = gvcurrentrow.Cells[1].Text.ToString();
string strEname = gvcurrentrow.Cells[2].Text.ToString();
pnlViewAbsence.Visible = true;
lblViewAbsence.Text = strEname;
grdViewAbsence.Visible = true;
string errorMsg = string.Empty;
ATService objClientEmp = new ATService();
DataSet dsEmpAbs = null;
String strEmpSID = CookieManager.Read("strEmpSID");
dsEmpAbs = objClientEmp.GetAbChkReqByEmpSID(strEmpSID, ref errorMsg);
if (dsEmpAbs != null)
{
if (dsEmpAbs.Tables.Count > 0)
{
if (dsEmpAbs.Tables[0].Rows.Count > 0)
{

grdViewAbsence.DataSource = dsEmpAbs.Tables[0];
grdViewAbsence.DataBind();
ViewState["ViewDataSource"] = dsEmpAbs.Tables[0];
lblViewAbsence.Visible = true;
}
else
{
pnlViewAbsence.Visible = false;
lblViewAbsence.Visible = false;
lblViewAbsence.Text = "There is no Absence Request ID";
}
}
}
}



}



protected void grdViewAbsence_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
grdViewAbsence.PageIndex = e.NewPageIndex;
grdViewAbsence.DataSource = (DataTable)ViewState["ViewDataSource"];
grdViewAbsence.DataBind();
}
catch (Exception ex)
{

}
}

protected void grdViewAbsence_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = ViewState["ViewDataSource"] as DataTable;

if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
grdViewAbsence.DataSource = ViewState["ViewDataSource"];
grdViewAbsence.DataBind();
}
}

public DataSet GetStatusNames()
{


string errorMsg = string.Empty;
ATService objClient = new ATService();

//DataSet dsMgrAltMgrNAme = objClient.GetEmployeeProfileByMgrAltMgrName("U5663 06", ref errorMsg);
String strEmpSID = CookieManager.Read("strEmpSID");
//DataSet dsStatus = objClient.GetAllEmployeeStatus(strEmpSID, ref errorMsg);
DataSet dsStatus = objClient.GetStatusByEmpSID(strEmpSID, ref errorMsg);
if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
DataRow orow = dsStatus.Tables[0].NewRow();
orow["Status"] = "All";
orow["Status"] = "0";
dsStatus.Tables[0].Rows.InsertAt(orow, 0);
//lblAbsenceRequestBy.Text = "Status Type - " + dsStatus.Tables[0].Rows[0][12].ToString();
//DropDownList ddlStatus = FindControl("ddlStatus") as DropDownList;
//DropDownList ddlStatus = grdChkStatus.HeaderRow.FindControl("ddlStatus") as DropDownList;
DropDownList ddlStatus = new DropDownList();
ddlStatus.DataSource = dsStatus.Tables[0];
//GridViewByStatus.DataSource = dsStatus.Tables[0];
//GridViewByStatus.DataBind();
//strEmpSID = dsMgrAltMgrNAme.Tables[0].Rows[0][0].ToString();

ddlStatus.DataTextField = "Status";
ddlStatus.DataValueField = "Status";
ddlStatus.DataBind();
//ViewState["DataSource"] = dsStatus.Tables[0];
return dsStatus;
}
}
return dsStatus;



}

public DataView GetStatusView(DataSet ds)
{

DataView dView = ds.Tables[0].DefaultView;
return dView;
}

public DataSet GetStatusDescriptions()
{
ATService objClient = new ATService();
string errorMsg = string.Empty;
String strEmpSID = CookieManager.Read("strEmpSID");
DataSet dsStatDesc = objClient.GetAbChkReqByEmpSID(strEmpSID, ref errorMsg);

if (dsStatDesc != null)
{
if (dsStatDesc.Tables.Count > 0)
{
if (dsStatDesc.Tables[0].Rows.Count > 0)
{
grdChkStatus.DataSource = dsStatDesc.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatDesc.Tables[0];
return dsStatDesc;
}
else
{
ShowAlert("No records found!");
grdChkStatus.Visible = false;
}
}
}




return dsStatDesc;

}



protected void ddlStatus_IndexChanged(object sender, EventArgs e)
{
//DropDownList ddlStatus = FindControl("ddlStatus") as DropDownList;
DropDownList ddlStatus = grdChkStatus.HeaderRow.FindControl("ddlStatus") as DropDownList;
string temp = ddlStatus.SelectedValue.ToString();


if (ddlStatus.SelectedValue == "0")
{

pnlViewAbsence.Visible = false;

grdChkStatus.Visible = true;
grdViewAbsence.Visible = false;


string errorMsg = string.Empty;
ATService objClient = new ATService();
String strEmpSID = CookieManager.Read("strEmpSID");
DataSet dsStatus = objClient.GetAbChkReqByEmpSID(strEmpSID, ref errorMsg);

if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
//AbsenceRequest objAbsReq = new AbsenceRequest();
//objAbsReq.StartDate = ConvertDatetoLocaleFormat(objAbsReq.StartDate);
//objAbsReq.EndDate = ConvertDatetoLocaleFormat(objAbsReq.EndDate);
//lblReportType.Text = "Status Type - All";// +dsStatus.Tables[0].Rows[0][12].ToString();
grdChkStatus.DataSource = dsStatus.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatus.Tables[0];
}
else
{
ShowAlert("No records found!");
}
}


}

else if (ddlStatus.SelectedValue == temp)
{
string strStatus = ddlStatus.SelectedValue.ToString();

pnlViewAbsence.Visible = false;

grdChkStatus.Visible = true;
grdViewAbsence.Visible = false;

string errorMsg = string.Empty;
ATService objClient = new ATService();
String strEmpSID = CookieManager.Read("strEmpSID");
//DataSet dsStatus = objClient.GetAbsReqStatusModByEmpSID("U394231", "Submit", ref errorMsg);
//DataSet dsStatus = objClient.GetAbsReqStatusModByEmpSID(strEmpSID, "Submit", ref errorMsg);
DataSet dsStatus = objClient.GetAbChkReqStatusByEmpSID(strEmpSID, strStatus, ref errorMsg);

if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
//AbsenceRequest objAbsReq = new AbsenceRequest();
//objAbsReq.StartDate = ConvertDatetoLocaleFormat(objAbsReq.StartDate);
//objAbsReq.EndDate = ConvertDatetoLocaleFormat(objAbsReq.EndDate);
//lblReportType.Text = "Status Type - " + dsStatus.Tables[0].Rows[0][12].ToString();
//dsStatus.Tables[0].Columns[].ColumnName.Remove;
grdChkStatus.DataSource = dsStatus.Tables[0];
grdChkStatus.DataBind();
ViewState["DataSource"] = dsStatus.Tables[0];
}
else
{
ShowAlert("No records found!");
}
}

}
}

#region custom method for alert popups

protected void ShowAlert(string Message)
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "MyAlert", "alert('" + Message + "');", true);
}
#endregion custom method for alert popups

protected void grdChkStatus_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{

string errorMsg = string.Empty;
ATService objClient = new ATService();

//DataSet dsMgrAltMgrNAme = objClient.GetEmployeeProfileByMgrAltMgrName("U5663 06", ref errorMsg);
String strEmpSID = CookieManager.Read("strEmpSID");
//DataSet dsStatus = objClient.GetAllEmployeeStatus(strEmpSID, ref errorMsg);
DataSet dsStatus = objClient.GetStatusByEmpSID(strEmpSID, ref errorMsg);
if (dsStatus!=null)
{
if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
DataRow orow = dsStatus.Tables[0].NewRow();
//orow["Status"] = "Select";
orow["Status"] = "All";
//orow["Status"] = "0";
//orow["Status"] = "0";
dsStatus.Tables[0].Rows.InsertAt(orow,0);
//dsStatus.Tables[0].Rows.InsertAt(orow, 1);
//dsStatus.Tables[0].Rows.InsertAt(orow, 2);
//lblAbsenceRequestBy.Text = "Status Type - " + dsStatus.Tables[0].Rows[0][12].ToString();
//DropDownList ddlStatus = (DropDownList)e.Row.Cells[0].Controls[0];//new DropDownList();
//DropDownList ddlStatus = new DropDownList();
DropDownList ddStatus = (DropDownList)e.Row.FindControl("ddlStatus");
string uniqueID= ddStatus.UniqueID;
int rowIndex =int.Parse(e.Row.RowIndex.ToString());
//ddlStatus = grdChkStatus.FindControl("ddlStatus") as DropDownList;
//ddlStatus = grdChkStatus.HeaderRow.FindControl("ddlStatus") as DropDownList;
//GridViewByStatus.DataSource = dsStatus.Tables[0];
//GridViewByStatus.DataBind();
//strEmpSID = dsMgrAltMgrNAme.Tables[0].Rows[0][0].ToString();
ddStatus.DataSource = dsStatus.Tables[0];
ddStatus.DataTextField = "Status";
ddStatus.DataValueField = "Status";
ddStatus.DataBind();
//ViewState["DataSource"] = dsStatus.Tables[0];
//return dsStatus;



}
}
//return dsStatus;

}
}
}

//private void BindGridView()
//{
// DataSet ds = GetStatusNames();
// DataView dv = GetStatusView(ds);
// string condition = null;

// if (grdChkStatus.HeaderRow != null)
// {
// DropDownList ddlStatus = (DropDownList)grdChkStatus.HeaderRow.FindControl(" ddlStatus");
// Status = ddlStatus.SelectedValue;


// if (ddlStatus.SelectedValue != "All")
// {
// condition = "Status='" + ddlStatus.SelectedValue + "'";
// }


// }


// if (condition != null)
// dv.RowFilter = condition;

// grdChkStatus.DataSource = dv;
// grdChkStatus.DataBind();
//}

protected void grdChkStatus_SelectedIndexChanged(object sender, EventArgs e)
{



//DropDownList ddlStatus = e.Row.FindControl("ddlStatus") as DropDownList;

string errorMsg = string.Empty;
ATService objClient = new ATService();

//DataSet dsMgrAltMgrNAme = objClient.GetEmployeeProfileByMgrAltMgrName("U5663 06", ref errorMsg);
String strEmpSID = CookieManager.Read("strEmpSID");
//DataSet dsStatus = objClient.GetAllEmployeeStatus(strEmpSID, ref errorMsg);
DataSet dsStatus = objClient.GetAbChkReqByEmpSID(strEmpSID, ref errorMsg);
if (dsStatus.Tables.Count > 0)
{
if (dsStatus.Tables[0].Rows.Count > 0)
{
DataRow orow = dsStatus.Tables[0].NewRow();
orow["Status"] = "All";
orow["Status"] = "0";
dsStatus.Tables[0].Rows.InsertAt(orow, 0);
//lblAbsenceRequestBy.Text = "Status Type - " + dsStatus.Tables[0].Rows[0][12].ToString();
DropDownList ddlStatus = FindControl("ddlStatus") as DropDownList;
ddlStatus.DataSource = dsStatus.Tables[0];
//GridViewByStatus.DataSource = dsStatus.Tables[0];
//GridViewByStatus.DataBind();
//strEmpSID = dsMgrAltMgrNAme.Tables[0].Rows[0][0].ToString();

ddlStatus.DataTextField = "Status";
ddlStatus.DataValueField = "Status";
ddlStatus.DataBind();

}

}
}
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter results by value in a gridview field cesemj ASP.NET 2.0 Basics 2 February 20th, 2008 11:39 PM
rs.filter in asp.net - Please help ivanv ASP.NET 2.0 Basics 0 May 13th, 2007 05:14 AM
Gridview Losing Filter on Edit mikeymikey ASP.NET 2.0 Professional 1 January 28th, 2007 05:55 AM
Filter GridView Results by date range srinredd59 ASP.NET 2.0 Basics 0 December 27th, 2006 03:53 PM
Filter/Search row in asp.net Grid ghari ASP.NET 1.0 and 1.1 Professional 2 February 8th, 2006 12:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.