c# gridview 修改问题
我想添加1个功能,能在原来的查询后的基础上,对部门这个字段可以实现修改功能,能在我现有的代码基础上添加。前台代码:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="请选择查询条件"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="name">姓名</asp:ListItem>
<asp:ListItem Value="no">工号</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="确定" onclick="Button1_Click"
style="height: 26px" />
<br />
<asp:Label
ID="Label2" runat="server"></asp:Label>
<br />
<br />
</div>
<asp:GridView ID="GridView1" runat="server" Height="132px" Width="307px">
</asp:GridView>
</form>
</body>
</html>
后台代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string sqlstr;
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=EMPDATA;Integrated Security=True");
con.Open();
if (DropDownList1.Text == "name")
{
sqlstr = "select Emp_Name as 姓名,Emp_No as 工号,Emp_department as 部门,Emp_Tel as 电话 from guest where Emp_Name like '%" + TextBox1.Text + "%'";
}
else
{
sqlstr = "select Emp_Name as 姓名,Emp_No as 工号,Emp_department as 部门,Emp_Tel as 电话 from guest where Emp_No like '%" + TextBox1.Text + "%'";
}
SqlDataAdapter mySA = new SqlDataAdapter(sqlstr,con);
DataSet ds = new DataSet();
mySA.Fill(ds,"ss");
GridView1.DataSource = ds;
GridView1.DataBind();
if (GridView1.Rows.Count == 0)
{
Label2.Text = "无符合数据";
}
else {
Label2.Text = " ";
}
}
}
c# --------------------编程问答-------------------- mySA.Update(ds);
? --------------------编程问答-------------------- 能有完整的前后台代码吗?
补充:.NET技术 , C#