带搜索按钮的Asp.net Gridview [英] Asp.net Gridview with search button

查看:72
本文介绍了带搜索按钮的Asp.net Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

单击搜索按钮后,我需要帮助在Gridview中显示记录.
我正在使用asp.net,c#.net和sql server.
我有一个带有Empid,empname文本框和一个Search按钮的Web表单,下面有一个Gridview来显示搜索结果.
我想在单击搜索按钮后将从EMP(empid,ename,....)表中获取的记录从数据库中提取到Gridview中.
谁能帮我.
谢谢您,

解决方案

在Aspx页面中创建静态Gridview,其中包含在Asp中显示名称所需的所有字段BoundField必须与Db数据匹配

 <   asp:gridview     id   ="     runat   =" 服务器" 允许分页   True"  autogeneratecolumns   ="    背景色  ="     bordercolor   黑色"  xmlns:asp   =" #unknown" >  <  /asp:gridview  >  



 <   > ; 
<  /列 >  



 <   asp:BoundField     DataField   ="   ="span> 
 
          HeaderStyle-Horizo​​ntalAlign   ="   HeaderText    EMPID" 
          InsertVisible   ="  true"  ItemStyle-Horizo​​ntalAlign   左侧"     ItemStyle-Width   ="  
 
         只读  ="  true"  SortExpression    EMPID" <   HeaderStyle     ="  左" / <   ItemStyle     ="  左" / <  /asp:BoundField  >  




 <   asp:BoundField     DataField   ="  
 
        HeaderStyle-Horizo​​ntalAlign   ="   HeaderText   ="  
          InsertVisible   ="  true"  ItemStyle-Horizo​​ntalAlign   左侧"     ItemStyle-Width   ="  
 
            ReadOnly   = "     SortExpression   ="  > 
    <   HeaderStyle     ="  左" / <   ItemStyle     ="  左" / 





像这样创建您的网格视图并在其后面编写代码,您必须与此Gridview绑定...


在Aspx.cs文件中


 DataTable dtsearch =  DataTable
dtsearch = SearchStudio();
          
              如果(dtsearch.Rows.Count >   0 )
              {
                  pnlStudioInfo.Visible =  true ;
                  gdvStudio.DataSource = dtsearch;
                  ViewState [" ] = dtsearch;
                  gdvStudio.DataBind();
              } 


请参考以下链接:
在具有搜索功能的GridView中显示大量数据 [ ^ ]-本文介绍了如何在ASP.NET
的GridView中显示大量数据和实现搜索功能 带有搜索选项(SearchableGridView)的ASP.NET GridView [ ^ ] -在页脚中带有搜索选项的ASP.NET GridView .
GridView-搜索控件 [


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,

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();
              }


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


//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();
}


这篇关于带搜索按钮的Asp.net Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆