假设我有 ProjectCode 文本框:
<td align="left" width="200px">
<asp:TextBox ID="TbProjectCode" runat="server" Width="194px"></asp:TextBox>
</td>
和一个图像按钮:
<asp:ImageButton ID="BtnSearch" runat="server" ImageUrl="../Support/Image/MagnifierGlass.png" Width="75%" Height="75%" OnClientClick="openNewWin();return false;" />
和一个网格视图:
<asp:Panel ID="PanelDGV" runat="server" Height="100%" ScrollBars="None" Width="100%">
<asp:GridView ID="DGV" runat="server" AutoGenerateColumns="False" GridLines="None" AllowPaging="true" PageSize="2" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:BoundField DataField="ProjectCode" HeaderText="Project Code" />
<asp:BoundField DataField="ProjectName" HeaderText="Project Name" />
<asp:ButtonField ButtonType="Image" ImageUrl="../Support/Image/Edit.png" ItemStyle-HorizontalAlign="Center" CommandName="CmdSearch" HeaderText="Edit">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
</asp:GridView>
</asp:Panel>
并且我正在使用带有查询的存储过程(我从另一个数据库中获取值,请注意 Master 中的双点..[MS_Project]):
SELECT [projectCode],[projectName]
FROM Master..[MS_Project]
WHERE [projectCode] like '%' + @ProjectCode + '%'
ORDER BY [projectCode] ASC
我想创建一个搜索功能,所以用户在文本框中输入他们想要的项目代码,然后单击图像按钮,然后搜索结果应该显示在gridview中,有没有这样做?谢谢你。
编辑
我在.vb中添加:
Protected Sub BtnSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnSearch.Click
Dim ds As New DataSet()
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("CfgConnectionString").ToString())
Using command As New SqlCommand()
command.CommandType = CommandType.StoredProcedure
command.CommandText = "msProject_Select"
command.Connection = connection
command.Parameters.AddWithValue("@ProjectCode", TbProjectCode.Text)
connection.Open()
Dim a As New SqlDataAdapter(command)
a.Fill(ds)
End Using
End Using
DGV2.DataSource = ds
DGV2.DataBind()
End Sub
结束类