| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 479 人关注过本帖
标题:c# gridview 更新功能问题
只看楼主 加入收藏
cmamy
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-4-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
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.

<html xmlns="http://www.
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="Label1" runat="server" Text="请选择查询条件"></asp:Label>
   
    &nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value="name">姓名</asp:ListItem>
            <asp:ListItem Value="no">工号</asp:ListItem>
        </asp:DropDownList>
&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" Text="确定" onclick="Button1_Click"
            style="height: 26px" />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label
            ID="Label2" runat="server"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <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 = " ";
        }
        
    }
}
搜索更多相关主题的帖子: server PUBLIC title 最好 
2013-04-08 21:25
mrhan1991
Rank: 2
等 级:论坛游民
威 望:1
帖 子:13
专家分:50
注 册:2013-4-2
收藏
得分:10 
用SqlCommandBuilder这个类型试试吧,你可以百度一下这个看看

Coding is life !
2013-04-09 08:22
party620
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:18
帖 子:696
专家分:2521
注 册:2013-1-31
收藏
得分:10 
在页面添加一个按钮,在查询前button的可用属性为false,在查询后button 的可用属性为true;然后接下来就是对Gridview操作
2013-04-09 08:42
快速回复:c# gridview 更新功能问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050715 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved