我有一个带有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();
}
}
答案 0 :(得分:0)
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>