2014-01-09 29 views
0

我有一个带有4个文本框和搜索按钮的jQuery对话框。我想从我的数据库中搜索一个值,然后在GridView中显示该值,每个文本框都有一个字符串@firstname@lastname@address@mobile用户可以在任何文本框中输入一个值,如果他们点击btnSearch_Click的值将显示在GridView中。使用多个文本框和搜索按钮从SQL数据库搜索数据

我希望你能理解我的问题(不擅长英语,不擅长编程)。

问题:如果用户在任何文本框的值的输入值将在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

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> 
+0

我得到一个新的错误'ConnectionString属性尚未initialized.''con.Open();' –

+0

你应该检查变量“strConnString”正在某处设置。我无法从你的代码中知道这是事实。 –