[英]Search data from SQL Database using multiple textbox and a Search Button
我有一個帶有4個文本框和一個搜索按鈕的jQuery對話框。 我想從數據庫中搜索一個值,然后在GridView中顯示該值,每個文本框都有一個字符串@firstname
@lastname
@address
@mobile
用戶可以在任何文本框中輸入一個值,如果他們單擊btnSearch_Click
值,則將在GridView中顯示。
我希望你能理解我的問題(不擅長英語和編程新手)。
問題:如果用戶在任何文本框中輸入一個值,則該值將顯示在gridview中,並且對話框應關閉
js:
<script type="text/javascript">
$(function () {
$("#Searchprod").dialog({
appendTo: "form",
autoOpen: false,
width: 630,
height: 350,
draggable: false,
resizable: false,
modal: true
});
$("#btnupregSearch").click(function () {
$("#Searchprod").dialog("open");
return false;
});
});
</script>
帶有文本框和按鈕的對話框:
<div id="Searchprod" title="Search User">
<asp:UpdatePanel runat="server" ID="Searchpanel" >
<ContentTemplate>
<table>
<tr>
<td><label class="label">By First Name</label></td>
<td><asp:TextBox ID="txtfn" runat="server" class="basetxt" ></asp:TextBox></td>
</tr>
<tr>
<td><label class="label">By Last Name</label></td>
<td><asp:TextBox ID="txtln" runat="server" class="basetxt" ></asp:TextBox></td>
</tr>
<tr>
<td><label class="label">By Address</label></td>
<td><asp:TextBox ID="txtadd" runat="server" class="basetxt"></asp:TextBox></td>
</tr>
<tr>
<td><label class="label">By Mobile</label></td>
<td><asp:TextBox ID="txtmobile" runat="server" class="basetxt" ></asp:TextBox></td>
</tr>
<tr>
<td><table>
<tr>
<td><asp:Button ID="btnSearch" runat="server" CausesValidation="false" Text="Search" class="submitbtn" onclick="btnSearch_Click" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><asp:UpdateProgress ID="updateprogress1" runat="server" AssociatedUpdatePanelID="Searchpanel" cla>
<ProgressTemplate></ProgressTemplate>
</asp:UpdateProgress></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
這是我嘗試過的,但是我認為它不起作用
按鍵:
protected void btnSearch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
SqlCommand com = new SqlCommand("find", con);
com.Parameters.Add("@firstname", SqlDbType.VarChar).Value = txtfn.Text;
com.Parameters.Add("@lastname", SqlDbType.VarChar).Value = txtln.Text;
com.Parameters.Add("@address", SqlDbType.VarChar).Value = txtadd.Text;
com.Parameters.Add("@mobile", SqlDbType.VarChar).Value = txtmobile.Text;
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sqlda = new SqlDataAdapter(com);
dt.Clear();
sqlda.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
updatepanel必須位於div#Searchprod的外部。 您現在擁有的方式,我認為div#Searchprod不會關閉。
<asp:UpdatePanel runat="server" ID="Searchpanel" >
<ContentTemplate>
<div id="Searchprod" title="Search User">
<table>
<tr>
<td><label class="label">By First Name</label></td>
<td><asp:TextBox ID="txtfn" runat="server" class="basetxt" ></asp:TextBox></td>
</tr>
<tr>
<td><label class="label">By Last Name</label></td>
<td><asp:TextBox ID="txtln" runat="server" class="basetxt" ></asp:TextBox></td>
</tr>
<tr>
<td><label class="label">By Address</label></td>
<td><asp:TextBox ID="txtadd" runat="server" class="basetxt"></asp:TextBox></td>
</tr>
<tr>
<td><label class="label">By Mobile</label></td>
<td><asp:TextBox ID="txtmobile" runat="server" class="basetxt" ></asp:TextBox></td>
</tr>
<tr>
<td><table>
<tr>
<td><asp:Button ID="btnSearch" runat="server" CausesValidation="false" Text="Search" class="submitbtn" onclick="btnSearch_Click" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><asp:UpdateProgress ID="updateprogress1" runat="server" AssociatedUpdatePanelID="Searchpanel" cla>
<ProgressTemplate></ProgressTemplate>
</asp:UpdateProgress></td>
</tr>
</table>
</ContentTemplate>
</div>
</asp:UpdatePanel>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.