Hey,
I wanted to generate a report (GenReport.aspx) containing the list of GridView items filtered from the entered data from report.aspx. When I was debugging, I selected the data I wanted to filter, but it shows me all the data on the table instead of the data filtered on the table.
GenReport.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn() { ColumnName = "AppTypeName", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "name", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "designation", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "OfficeName", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "floorNo", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "DeptName", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "projectType", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "emailDiversionType", DataType = typeof(string) });
dt.Columns.Add(new DataColumn() { ColumnName = "IntAccess", DataType = typeof(bool) });
dt.Columns.Add(new DataColumn() { ColumnName = "nsf", DataType = typeof(bool) });
dt.Columns.Add(new DataColumn() { ColumnName = "loanComp", DataType = typeof(bool) });
dt.Columns.Add(new DataColumn() { ColumnName = "Date", DataType = typeof(DateTime) });
string AppTypeName = Request.QueryString["status"];
string name = Request.QueryString["name"];
string designation = Request.QueryString["designation"];
string OfficeName = Request.QueryString["office"];
string floorNo = Request.QueryString["floor"];
string DeptName = Request.QueryString["dept"];
string projectType = Request.QueryString["project"];
string emailDiversionType = Request.QueryString["emailDiv"];
bool IntAccess = false;
bool nsf = false;
bool loanComp = false;
if (Request.Form["IA"] != null && Request.Form["IA"] == "true")
{
IntAccess = true;
}
if (Request.Form["NSF"] != null && Request.Form["NSF"] == "true")
{
nsf = true;
}
if (Request.Form["LC"] != null && Request.Form["LC"] == "true")
{
loanComp = true;
}
dt.Rows.Add(AppTypeName, name, designation, OfficeName, floorNo, DeptName, projectType, emailDiversionType, IntAccess, nsf, loanComp, DateTime.Now);
// I have made the Date as DateTime.Now
FormView1.DataSource = dt;
FormView1.DataBind();
}
}
GenReport.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GenReport.aspx.cs" Inherits="IT_application_form_v4.admin.GenReport" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
text-decoration: underline;
}
.auto-style4 {
width: 20px;
}
.auto-style5 {
width: 87px;
}
.auto-style6 {
width: 233px;
}
.auto-style7 {
width: 255px;
}
.auto-style8 {
width: 171px;
}
.auto-style9 {
width: 230px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="PrintButton" runat="server" Text="Print" OnClientClick="javascript:window.print();"/>
<div align="center">
<!--<asp:Image ID="mmcGamudaLogo" runat="server" Height="94px" ImageAlign="Middle" ImageUrl="img/mmc-gamuda logo large.png" style="text-align: center" /><br />-->
<strong>APPLICANT LIST</strong>
</div>
<div class="panel panel-default">
<div class="panel-body">
<asp:FormView ID="FormView1" runat="server">
<ItemTemplate>
<strong>Printed On: </strong>
<asp:Label ID="printDateTime" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
<br />
<strong>Printed By: </strong>
<hr />
<span class="auto-style1"><strong>FILTERS:</strong></span><br />
<table style="width: 100%;">
<tr>
<td class="auto-style8"><b>Status:</b></td>
<td class="auto-style9">
<asp:Label ID="StatusLbl" runat="server" Text='<%# Eval("AppTypeName") %>'></asp:Label>
</td>
<td class="auto-style4" rowspan="3"> </td>
<td class="auto-style5"><b>Office:</b></td>
<td class="auto-style6">
<asp:Label ID="OfficeLbl" runat="server" Text='<%# Eval("OfficeName") %>'></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style8"><b>Name (starts with):</b></td>
<td class="auto-style9">
<asp:Label ID="nameLbl" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</td>
<td class="auto-style5"><b>Floor:</b></td>
<td class="auto-style6">
<asp:Label ID="FloorLbl" runat="server" Text='<%# Eval("floorNo") %>'></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style8"><b>Designation (starts with):</b></td>
<td class="auto-style9">
<asp:Label ID="designationLbl" runat="server" Text='<%# Eval("designation") %>'></asp:Label>
</td>
<td class="auto-style5"><b>Department:</b></td>
<td class="auto-style6">
<asp:Label ID="DeptLbl" runat="server" Text='<%# Eval("DeptName") %>'></asp:Label>
</td>
</tr>
</table>
<hr />
<b>Project: </b>
<asp:Label ID="ProjectLbl" runat="server" Text='<%# Eval("projectType") %>'></asp:Label>
<br />
<strong>E-mail Diversion:</strong>
<asp:Label ID="emailDiversionLbl" runat="server" Text='<%# Eval("emailDiversionType") %>'></asp:Label>
<hr />
<table style="width: 100%;">
<tr>
<td><b>Internet Access: </b>
<asp:CheckBox ID="IntAccessCheckBox" runat="server" Enabled="false" Checked='<%# Eval("IntAccess") %>' /></td>
<td><b>Network Shared Folder: </b>
<asp:CheckBox ID="nsfCheckBox" runat="server" Enabled="false" Checked='<%# Eval("nsf") %>' /></td>
<td><b>Loan Computer: </b>
<asp:CheckBox ID="loanCompCheckBox" runat="server" Enabled="false" Checked='<%# Eval("loanComp") %>' /></td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
</div>
</div>
<br />
<div>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="AppTypeName" HeaderText="Status" SortExpression="AppTypeName" />
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
<asp:BoundField DataField="designation" HeaderText="Designation" SortExpression="designation" />
<asp:BoundField DataField="OfficeName" HeaderText="Office" SortExpression="OfficeName" />
<asp:BoundField DataField="floorNo" HeaderText="Floor" SortExpression="floorNo" />
<asp:BoundField DataField="DeptName" HeaderText="Dept" SortExpression="DeptName" />
<asp:BoundField DataField="projectType" HeaderText="Project" SortExpression="projectType" />
<asp:CheckBoxField DataField="EmailID" HeaderText="E-mail ID" SortExpression="EmailID" />
<asp:CheckBoxField DataField="EmailGroup" HeaderText="E-mail Group" SortExpression="EmailGroup" />
<asp:BoundField DataField="EmailGroupName" HeaderText="E-mail Group Name" SortExpression="EmailGroupName" />
<asp:BoundField DataField="emailDiversionType" HeaderText="E-mail Div" SortExpression="emailDiversionType" />
<asp:BoundField DataField="emailDiversionAdd" HeaderText="E-mail Div ID" SortExpression="emailDiversionAdd" />
<asp:CheckBoxField DataField="IntAccess" HeaderText="I.A." SortExpression="IntAccess" />
<asp:CheckBoxField DataField="nsf" HeaderText="N.S.F." SortExpression="nsf" />
<asp:CheckBoxField DataField="loanComp" HeaderText="L.C." SortExpression="loanComp" />
<asp:BoundField DataField="remarks" HeaderText="Remarks" SortExpression="remarks" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IT-app-v4-ConnectionString %>" SelectCommand="SELECT * FROM [Applicant]" FilterExpression="[AppTypeName] LIKE '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="AppTypeName" ControlID="FormView1$StatusLbl" PropertyName="text"/>
<asp:ControlParameter Name="name" ControlID="FormView1$nameLbl" PropertyName="text"/>
<asp:ControlParameter Name="designation" ControlID="FormView1$designationLbl" PropertyName="text"/>
<asp:ControlParameter Name="OfficeName" ControlID="FormView1$OfficeLbl" PropertyName="text"/>
<asp:ControlParameter Name="floorNo" ControlID="FormView1$FloorLbl" PropertyName="text"/>
<asp:ControlParameter Name="DeptName" ControlID="FormView1$DeptLbl" PropertyName="text"/>
<asp:ControlParameter Name="projectType" ControlID="FormView1$ProjectLbl" PropertyName="text"/>
<asp:ControlParameter Name="emailDiversionType" ControlID="FormView1$emailDiversionLbl" PropertyName="text"/>
<asp:ControlParameter Name="IntAccess" ControlID="FormView1$IntAccessCheckBox" PropertyName="Checked"/>
<asp:ControlParameter Name="nsf" ControlID="FormView1$nsfCheckBox" PropertyName="Checked"/>
<asp:ControlParameter Name="loanComp" ControlID="FormView1$loanCompCheckBox" PropertyName="Checked"/>
</FilterParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
report.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GenerateBtn_Click(object sender, EventArgs e)
{
string url = "GenReport.aspx?status=" + status.SelectedValue + "&name=" + name.Text + "&designation=" + designation.Text + "&office=" + office.SelectedValue + "&floor=" + floor.SelectedValue + "&dept=" + dept.SelectedValue + "&project=" + project.SelectedValue + "&emailDiv=" + emailDiv.SelectedValue + "&IA=" + IA.Checked + "&NSF=" + NSF.Checked + "&LC=" + LC.Checked;
Response.Redirect(url);
}
report.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="report.aspx.cs" Inherits="IT_application_form_v4.admin.report" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<br />
<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">FILTER BY</h3></div>
<div class="panel-body">
<br />
<table style="width:100%;">
<tr>
<td class="modal-sm" style="width: 350px"><strong>STATUS:</strong></td>
<td rowspan="7" style="width: 33px"> </td>
<td style="width: 177px"><strong>OFFICE:</strong></td>
<td>
<asp:DropDownList ID="office" runat="server" CssClass="form-control" Width="300px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Menara Gamuda</asp:ListItem>
<asp:ListItem>Menara MK</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="modal-sm" style="width: 350px">
<asp:DropDownList ID="status" runat="server" CssClass="form-control" Width="300px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Transfer</asp:ListItem>
<asp:ListItem>Existing</asp:ListItem>
</asp:DropDownList>
</td>
<td style="width: 177px"><strong>FLOOR:</strong></td>
<td>
<asp:DropDownList ID="floor" runat="server" CssClass="form-control" Width="300px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>13</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>17</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="modal-sm" style="width: 350px"><strong>NAME (Starts with):</strong></td>
</tr>
<tr>
<td class="modal-sm" style="height: 11px; width: 350px">
<asp:TextBox ID="name" runat="server" CssClass="form-control" Width="275px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="modal-sm" style="height: 11px; width: 350px">
</td>
<td style="height: 11px; width: 177px"><strong>DEPARTMENT:</strong></td>
<td style="height: 11px">
<asp:DropDownList ID="dept" runat="server" CssClass="form-control" Width="300px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Contracts & Commercial</asp:ListItem>
<asp:ListItem>Design & Technical</asp:ListItem>
<asp:ListItem>Finance</asp:ListItem>
<asp:ListItem>Human Resources & Administration</asp:ListItem>
<asp:ListItem>Information Technology</asp:ListItem>
<asp:ListItem>Operations</asp:ListItem>
<asp:ListItem>Project Management</asp:ListItem>
<asp:ListItem>Safety & Health</asp:ListItem>
<asp:ListItem>Systems</asp:ListItem>
<asp:ListItem>Tunnel</asp:ListItem>
<asp:ListItem>Underground Station</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="modal-sm" style="width: 350px"><strong>DESIGNATION (Starts with):</strong></td>
</tr>
<tr>
<td class="modal-sm" style="width: 350px">
<asp:TextBox ID="designation" runat="server" CssClass="form-control" Width="275px"></asp:TextBox>
</td>
<td style="width: 177px"> </td>
<td>
</td>
</tr>
</table>
</div>
<div class="panel-body">
<table style="width:100%;">
<tr>
<td style="width: 230px"><b>PROJECT:</b></td>
<td>
<asp:DropDownList ID="project" runat="server" CssClass="form-control" Width="300px">
<asp:ListItem></asp:ListItem>
<asp:ListItem>EDTP</asp:ListItem>
<asp:ListItem>KVMRT (UG)</asp:ListItem>
<asp:ListItem>KVMRT (PDP)</asp:ListItem>
<asp:ListItem>Others</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 230px"><b>E-MAIL DIVERSION:</b></td>
<td>
<asp:DropDownList ID="emailDiv" runat="server" CssClass="form-control" Width="300px" DataTextField="desc" DataValueField="emailDiversionType">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="NONE">None</asp:ListItem>
<asp:ListItem Value="M2G">MGJV to Gamuda</asp:ListItem>
<asp:ListItem Value="G2M">Gamuda to MGJV</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
</table>
</div>
<div class="panel-body">
<table style="width: 100%;">
<tr>
<td style="width: 182px"><strong>Internet Access: </strong><asp:CheckBox ID="IA" runat="server" /></td>
<td style="width: 217px"><strong>Network Shared Folder: </strong><asp:CheckBox ID="NSF" runat="server" /></td>
<td><strong>Loan Computer: </strong><asp:CheckBox ID="LC" runat="server" /></td>
</tr>
</table>
</div>
<div class="panel-body"><asp:Button ID="GenerateBtn" runat="server" Text="Generate" CssClass="btn btn-primary" OnClick="GenerateBtn_Click"/></div>
</div>
</asp:Content>
MDF files (required to connect): https://drive.google.com/file/d/0B07_pOHhTox3YnBRUTNfbXJUYnc/view?usp=sharing