<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 248px; WIDTH: 624px; POSITION: absolute; TOP: 104px; HEIGHT: 272px"
cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD style="HEIGHT: 51px" align="center" colSpan="2">员工信息模糊查询</TD>
</TR>
<TR>
<TD style="WIDTH: 222px; HEIGHT: 46px">请选择查询类型:</TD>
<TD style="HEIGHT: 46px"><asp:dropdownlist id="search_type" Runat="server">
<asp:ListItem Value="姓名" Selected="True"></asp:ListItem>
<asp:ListItem Value="性别"></asp:ListItem>
<asp:ListItem Value="籍贯"></asp:ListItem>
<asp:ListItem Value="民族"></asp:ListItem>
<asp:ListItem Value="学历"></asp:ListItem>
<asp:ListItem Value="部门"></asp:ListItem>
</asp:dropdownlist></TD>
</TR>
<TR>
<TD style="WIDTH: 222px; HEIGHT: 44px">请输入查询内容:</TD>
<TD style="HEIGHT: 44px"><asp:textbox id="txtcontent" Runat="server"></asp:textbox><asp:button id="button1" Runat="server" Text="确定"></asp:button></TD>
</TR>
<tr>
<td style="HEIGHT: 41px" align="center" colSpan="2"><FONT face="宋体">查询结果显示</FONT></td>
</tr>
<tr>
<td colSpan="2"><asp:datagrid id="grid_show" Runat="server" AutoGenerateColumns="False" GridLines="None" Width="616px"
AllowSorting="True" AllowPaging="True" CellPadding="2">
<SelectedItemStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedItemStyle>
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" BackColor="Tan"></HeaderStyle>
<FooterStyle BackColor="Tan"></FooterStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="users_id" DataNavigateUrlFormatString="person_detail.aspx?users_id={0}"
DataTextField="users_id" HeaderText="员工编号">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="username" SortExpression="username" HeaderText="姓名">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="sex" SortExpression="sex" HeaderText="性别">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="hometown" SortExpression="hometown" HeaderText="籍贯">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="nation" SortExpression="nation" HeaderText="民族">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="dep_name" SortExpression="dep_name" HeaderText="部门">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="users_id" HeaderText="users_id"></asp:BoundColumn>
</Columns>
</asp:datagrid></td>
</tr>
</TABLE>
这是.aspx,
如何实现这个查询啊?
private void button1_Click(object sender, System.EventArgs e)
{
if(search_type.SelectedIndex>-1&&txtcontent.Text!=null)
{
sign="%";
}
BindGrid();
}
private void BindGrid()
{
string sqlstr="select users_id,username,sex,hometown,nation,dep_name from users,dep where users.dep_id=dep.dep_id";
sqlstr += " and " + search_type.SelectedValue + " like '" + sign + txtcontent.Text.ToString().Trim() + sign + "' "; //这个对吗?
da=new SqlDataAdapter(sqlstr,conn);
conn.Open();
ds=new DataSet();
da.Fill(ds);
DataView dv=ds.Tables[0].DefaultView;
grid_show.DataSource=dv;
grid_show.DataBind();
}