Sean, we need to simulate the functionality ajax control toolkit in ASP .NET
Herez the sample code with EmployeeID and Name.
<body>
<form id="form1" runat="server">
<div>
<table style="width: 640px" border="0" cellpadding="0" cellspacing="6" class="GridviewTable">
<tr >
<td style="width: 120px">
Employee ID
</td>
<td style="width: 120px">
Employee Name
</td>
</tr>
<tr >
<td style="width: 120px;">
<asp:TextBox ID="txtEmpId" runat="server" Width="75px"></asp:TextBox>
<asp:Button ID="btnEmpId" runat="server" Text="IDFilter" onclick="btnIdClick" />
</td>
<td style="width: 120px;">
<asp:TextBox ID="txtEmpName" runat="server" Width="75px"></asp:TextBox>
<asp:Button ID="btnEmpName" runat="server" Text="NameFilter" onclick="btnNameClick" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="gvEmp" runat="server" AutoGenerateColumns="False" Width="640px" ShowHeader="False" >
<Columns>
<asp:BoundField DataField="EmpId" ItemStyle-Width="120px" >
<ItemStyle Width="120px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="EmpName" ItemStyle-Width="120px" >
<ItemStyle Width="120px"></ItemStyle>
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
In code behind System.Data.DataTable plays the major role. Generate the local data table and change the result set during filter button clicked event.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
EmpTable = new EmpTable();
empTable = CreateDataTable();
Session["EmpTable"] = empTable;
this.gvEmp.DataSource = ((DataTable)Session["EmpTable"]).DefaultView;
this.gvEmp.DataBind();
}
}
private DataTable CreateDataTable()
{
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "EmpId";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "EmpId";
myDataTable.Columns.Add(myDataColumn);
myDataTable.Rows.Add("111", "aaaaaa");
return myDataTable;
}
protected void btnIdClick(object sender, EventArgs e)
{
if (txtEmpId.Text.ToString().Trim() != "")
{
DataTable dt = (DataTable)Session["EmpTable"];
var linquery = from tbl in dt.AsEnumerable()
where tbl.Field("EmpId").StartsWith(txtProductId.Text.ToString().Trim())
select t;
DataTable dtable = new DataTable();
dtable = linquery.CopyToDataTable();
this.gvEmp.DataSource = dtable;
this.gvEmp.DataBind();
}
else
{
this.gvEmp.DataSource = ((DataTable)Session["EmpTable"]).DefaultView;
this.gvEmp.DataBind();
}
}