Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi All,
 
I need a help to display records in Gridview after clicking search button.
I am using asp.net and c#.net and sql server.
I have a web form with empid,empname textboxes with one Search button and below I have a Gridview to display search results.
I want to dipslay records fetching from EMP(empid,ename,....) table from database into the Gridview after clicking search button.
Can anyone Help me.
Thank you,
Posted 3-Jun-12 23:44pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please refer following links:
Display Large Amount of Data in GridView with Search Functionality[^] -This article explains how to display large amount of data and implement search functionality in GridView in ASP.NET
ASP.NET GridView with search option (SearchableGridView)[^] -An ASP.NET GridView with a search option in the footer.
GridView-Search Control[^] -Search control with basic/advanced modes for DataTable filtering capabilities
  Permalink  
Comments
thatraja at 4-Jun-12 15:57pm
   
5!
Prasad_Kulkarni at 5-Jun-12 0:08am
   
Thank you thatRaja!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Create A Static Gridview in Aspx Page with All The Field You Required to Display Names In Asp BoundField Must Match with Db Data
 
<asp:gridview id="gdvStudio" runat="server" allowpaging="True" autogeneratecolumns="False" backcolor="White" bordercolor="Black" xmlns:asp="#unknown"></asp:gridview>
 
<columns>
</columns>
 
<asp:BoundField DataField="EMPID"
    HeaderStyle-HorizontalAlign="Left" HeaderText="EMPID"
    InsertVisible="true" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="300"
    ReadOnly="true" SortExpression="EMPID">
    <HeaderStyle HorizontalAlign="Left" />
    <ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
 

<asp:BoundField DataField="COLUMN2"
   HeaderStyle-HorizontalAlign="Left" HeaderText="COLUMN2"
    InsertVisible="true" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="300"
     ReadOnly="true" SortExpression="COLUMN2">
    <HeaderStyle HorizontalAlign="Left" />
    <ItemStyle HorizontalAlign="Left" />
&lt;/asp:BoundField>
 
  
     
 

 
Create Your Grid View Like This and CodeBehind You Have to bind with this Gridview...
 

In Aspx.cs file
 

DataTable dtsearch=new DataTable 
dtsearch = SearchStudio();
          
              if (dtsearch.Rows.Count > 0)
              {
                  pnlStudioInfo.Visible = true;
                  gdvStudio.DataSource = dtsearch;
                  ViewState["file"] = dtsearch;
                  gdvStudio.DataBind();
              }
 
  Permalink  
Comments
jaipal0908 at 4-Jun-12 6:20am
   
Hi Tony,
I designed the page with one search text box empid and search button and Gridview.
But I want the code in search button click to bind the Gridview.
Can you help me.
Tony Tom.k at 12-Jun-12 5:59am
   
Hi Jaipal You are using stored procedures or you are directly using select queries.....
Use This Code Inside Button Click
 
DataTable dtsearch=new DataTable
dtsearch = SearchStudio();

if (dtsearch.Rows.Count > 0)
{
pnlStudioInfo.Visible = true;
gdvStudio.DataSource = dtsearch;
ViewState["file"] = dtsearch;
gdvStudio.DataBind();
}
Tony Tom.k at 12-Jun-12 6:00am
   
IF its not getting triggered use this trigger Inside your
Aspx page....
 
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click">
</Triggers>
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

//code 4 search btn
protected void btnsearch_Click(object sender, EventArgs e)
{
SqlConnection con;
con = new SqlConnection("TypeConnectionStringHere");
con.Open();
string c = txtcity.Text;
string str;
str="select * from TableName where city=" + c + "";
//city is the column name in table
SqlCommand cmd;
cmd=new SqlCommand(str,con);
SqlDataReader dr;
dr=cmd.ExecuteReader();
if(dr.Read())
{
 
txtcity.Text=dr.GetString(0);
//if city is in 0 index of table
}
else
{
Response.Write("City does not exist");
txtc.Text="";
}
dr.Close();
con.Close();
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is a vast question to be answer,
If you have tried something and got some error then let us know. The people here will help you out from that.
 
Here you should connect to the database and the next process of searching the record can be done in two ways -
1. Either you write the SqlCommand at front end to search for the entries textboxes. Refer this -> http://asp-net-example.blogspot.in/2008/11/aspnet-sqlcommand-example-how-to-use.html[^]
 
2.Else you can write the procedure and call that procedure with the input parameter as the search criteria Refer this-http://forums.codeguru.com/showthread.php?threadid=373179[^]
 
you will get the result in the Dataset which you have to bind to the Grid view.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

when you click on search button than Get the data by query(filter the records by textbox value) then bind this data to gridview.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 2 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100