Hi, Amol111
HTML
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div style="overflow: hidden; overflow-x: scroll; height: auto; width: 98%">
<br />
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button ID="btnSearch" Text="Search" OnClick="OnSearch" runat="server" />
<asp:UpdatePanel ID="UpdatePanel11" runat="server">
<ContentTemplate>
<asp:Panel ID="pnlMsg" runat="server" BackColor="white" Height="150px" Width="300px"
Style="display: none">
<table style="width: 100%; border: Solid 2px #D46900; width: 100%; height: 100%;
font-family: Verdana; font-size: small">
<tr style="background-image: url(Images/header.gif)">
<td style="height: 10%; color: White; font-weight: bold; padding: 3px; font-size: larger;
font-family: Calibri" align="Left">
Message Box
</td>
<td style="color: White; font-weight: bold; padding: 3px; font-size: larger" align="Right">
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="Images/Close.gif" Style="border: 0px"
align="right" />
</td>
</tr>
<tr>
<td colspan="2" align="center" style="padding: 5px; text-align: center">
</td>
</tr>
<tr>
<td colspan="2" align="center" style="padding: 5px; text-align: center">
<asp:Label ID="lblpmsg" runat="server" /><br />
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td style="text-align: center" colspan="2">
<asp:Button ID="Button1" runat="server" Text="OK!!" CssClass="btnokpopup" />
</td>
</tr>
<tr>
<td colspan="2" align="center" style="padding: 5px; text-align: center">
</td>
</tr>
<asp:TextBox ID="txtSortingName" runat="server" Visible="false"></asp:TextBox>
<asp:TextBox ID="txtGridSortFlow" runat="server" Visible="false" AutoPostBack="True"></asp:TextBox>
</table>
<br />
</asp:Panel>
<asp:GridView ID="gvdEncashment" runat="server" AllowSorting="True" AutoGenerateColumns="False"
AutoGenerateSelectButton="True" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging"
DataKeyNames="CgNo" PageSize="3">
<HeaderStyle CssClass="FixedHeader" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" CssClass="FixedHeader" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="left" />
<RowStyle BackColor="#EFF3FB" Height="21px" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<%-- <asp:TemplateField HeaderText="Financial Year" ControlStyle-Width="90px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="Fy" runat="server" Text='<%#Eval("Fy") %>' />
</ItemTemplate>
<ControlStyle Width="80px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="CgNo" ControlStyle-Width="60px" ItemStyle-HorizontalAlign="Center"
SortExpression="CgNo">
<ItemTemplate>
<asp:Label ID="id" runat="server" Text='<%#Eval("CgNo") %>' />
</ItemTemplate>
<ControlStyle Width="60px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="CG Date" ControlStyle-Width="150px" ItemStyle-HorizontalAlign="Center"
Visible="false">
<ItemTemplate>
<asp:Label ID="CgDate" runat="server" Text='<%#Eval("CgDate","{0:dd MMM yyyy}") %>' />
</ItemTemplate>
<ControlStyle Width="150px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="CbNo" ControlStyle-Width="80px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="CbNo" runat="server" Text='<%#Eval("CbNo") %>' />
</ItemTemplate>
<ControlStyle Width="80px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="CbDate" ControlStyle-Width="150px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="CbDate" runat="server" Text='<%#Eval("CbDate","{0:dd MMM yyyy}") %>' />
</ItemTemplate>
<ControlStyle Width="150px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ControlStyle-Width="250px" ItemStyle-HorizontalAlign="Left"
SortExpression="Name">
<ItemTemplate>
<asp:Label ID="Name" runat="server" Text='<%#Eval("Name") %>' />
</ItemTemplate>
<ControlStyle Width="250px"></ControlStyle>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Designation" ControlStyle-Width="350px" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="Designation" runat="server" Text='<%#Eval("Designation") %>' />
</ItemTemplate>
<ControlStyle Width="350px"></ControlStyle>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Dopt No" ControlStyle-Width="70px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="DoptNo" runat="server" Text='<%#Eval("DoptNo") %>' />
</ItemTemplate>
<ControlStyle Width="70px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="DoptDate" ControlStyle-Width="150px" ItemStyle-HorizontalAlign="Center"
Visible="false">
<ItemTemplate>
<asp:Label ID="DoptDate" runat="server" Text='<%#Eval("DoptDate","{0:dd MMM yyyy}") %>' />
</ItemTemplate>
<ControlStyle Width="150px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Pay" ControlStyle-Width="115px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="Pay" runat="server" Text='<%#Eval("Pay") %>' />
</ItemTemplate>
<ControlStyle Width="115px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Gp" ControlStyle-Width="115px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="Gp" runat="server" Text='<%#Eval("Gp") %>' />
</ItemTemplate>
<ControlStyle Width="115px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="DaRate" ControlStyle-Width="90px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="DaRate" runat="server" Text='<%#Eval("DaRate") %>' />
</ItemTemplate
<ControlStyle Width="90px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>--%>
<%-- <asp:TemplateField HeaderText="DaAmount" ControlStyle-Width="90" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="DaAmount" runat="server" Text='<%#Eval("DAAmt") %>' />
</ItemTemplate>
<ControlStyle Width="90px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="ElDays" ControlStyle-Width="50px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="ElDays" runat="server" Text='<%#Eval("ElDays") %>' />
</ItemTemplate>
<ControlStyle Width="50px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="BillAmount" ControlStyle-Width="115px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="BillAmount" runat="server" Text='<%#Eval("BillAmt") %>' />
</ItemTemplate>
<ControlStyle Width="115px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="IT Percent" ControlStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="itper" runat="server" Text='<%#Eval("itper") %>' />
</ItemTemplate>
<ControlStyle Width="60px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="IncomeTax" ControlStyle-Width="50px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="IncomeTax" runat="server" Text='<%#Eval("IncomeTax") %>' />
</ItemTemplate>
<ControlStyle Width="50px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Cess" ControlStyle-Width="70px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="Cess" runat="server" Text='<%#Eval("Cess") %>' />
</ItemTemplate>
<ControlStyle Width="70px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="TotalTax" ControlStyle-Width="115px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="TotalTax" runat="server" Text='<%#Eval("TotalTax") %>' />
</ItemTemplate>
<ControlStyle Width="115px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="NetAmt" ControlStyle-Width="130px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="NetAmt" runat="server" Text='<%#Eval("NetAmt") %>' />
</ItemTemplate>
<ControlStyle Width="130px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="BPAmt " ControlStyle-Width="115px" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:Label ID="BPAmt" runat="server" Text='<%#Eval("BPAmt") %>' />
</ItemTemplate>
<ControlStyle Width="115px"></ControlStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="BPDate" ControlStyle-Width="150px" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<asp:Label ID="BPDate" runat="server" Text='<%#Eval("BPDate","{0:dd MMM yyyy}") %>' />
</ItemTemplate>
<ControlStyle Width="150px"></ControlStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="BPCheqNo" ControlStyle-Width="300px" ItemStyle-HorizontalAlign="left">
<ItemTemplate>
<asp:Label ID="BPCheqNo" runat="server" Text='<%#Eval("BPChqNo") %>' />
</ItemTemplate>
<ControlStyle Width="300px"></ControlStyle>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.Add("Fy", typeof(string));
dt.Columns.Add("CgNo", typeof(int));
dt.Columns.Add("CgDate", typeof(DateTime));
dt.Columns.Add("CbNo", typeof(int));
dt.Columns.Add("CbDate", typeof(DateTime));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Designation", typeof(string));
dt.Columns.Add("DoptNo", typeof(int));
dt.Columns.Add("DoptDate", typeof(DateTime));
dt.Columns.Add("Pay", typeof(string));
dt.Columns.Add("Gp", typeof(string));
dt.Columns.Add("ElDays", typeof(string));
dt.Columns.Add("BillAmt", typeof(double));
dt.Columns.Add("itper", typeof(string));
dt.Columns.Add("IncomeTax", typeof(double));
dt.Columns.Add("Cess", typeof(string));
dt.Columns.Add("TotalTax", typeof(double));
dt.Columns.Add("NetAmt", typeof(double));
dt.Columns.Add("BPAmt", typeof(double));
dt.Columns.Add("BPDate", typeof(DateTime));
dt.Columns.Add("BPChqNo", typeof(int));
dt.Rows.Add("1data", 1, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 2, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 3, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 4, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 5, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 6, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 7, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 8, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 9, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 10, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 11, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 12, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 13, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
dt.Rows.Add("1data", 14, DateTime.Now, 21, DateTime.Now, "PETER", "Testing", 101, DateTime.Now, "1000", "A", "21", 1000, "TEST", 200, "CSS", 121000, 101010, 10101, DateTime.Now, 344332);
gvdEncashment.DataSource = dt;
gvdEncashment.DataBind();
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.PopulateGridByIndex(e.NewPageIndex);
}
private void PopulateGridByIndex(int index)
{
this.gvdEncashment.PageIndex = index;
this.BindGrid();
}
protected void OnSearch(object sender, EventArgs e)
{
bool isSatisfied = false;
int index = gvdEncashment.PageIndex;
for (int i = 0; i < gvdEncashment.PageCount; i++)
{
PopulateGridByIndex(i);
foreach (GridViewRow row in this.gvdEncashment.Rows)
{
if ((row.FindControl("id") as Label).Text == this.txtSearch.Text.Trim())
{
gvdEncashment.SelectRow(row.RowIndex);
row.BackColor = Color.PeachPuff;
isSatisfied = true;
break;
}
}
if (isSatisfied)
{
break;
}
}
if (!isSatisfied)
{
PopulateGridByIndex(index);
}
}
Screenshot