惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 夜飞

滚动DATAGRID数据 和股票一样滚动 vs.2005 中对COOKIES 加密解密 例子 - 夜飞 asp.net(c#) datelist DataGrid 中截取字符串加"..." 和 鼠标放上去字符全部显示 - 夜飞 vs.2005 比较时间大小 可精确到秒 - 夜飞 VS.2005 子窗体提交数据刷新父窗体 GRIDVIEW 子窗体(2) VS.2005 子窗体提交数据刷新父窗体 GRIDVIEW 父窗体(1) - 夜飞 创建数据库连接对象 ASP.NET程序员笔试最常见问题 海量数据库的查询优化及分页算法方案 - 夜飞 表格列头加菜单(datagrid) 实现无刷新DropdownList联动效果 实现的不让同一个用户登陆 GridView控件修改、删除示例(修改含有DropDownList控件) asp.net打印 Web打印控制技术的几种方案: ASP.NET中弹出窗口技术 在asp.net中读取XML文件信息的4种方法 Asp.Net 动态生成验证码 ----- 把DataGrid1的一列的统计显示在页脚
gridview中加弹出窗口用例
夜飞 · 2006-07-12 · via 博客园 - 夜飞

。CS
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class System_ManageDepartment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = null;
            BindGridView();
        }
    }

    protected void ImgDepartment_Click(object sender, ImageClickEventArgs e)
    {
        if (!JS.isCookiesAvailabile())
        {
            return;
        }

        //插入部门名称的SQL语句
        StringBuilder strsql = new StringBuilder("INSERT INTO DICT_DEPARTMENT(DEPARTMENTNAME) VALUES('")
                               .Append(txbDepartment.Text.Trim())
                               .Append("')");

        try
        {
            if (txbDepartment.Text.Trim() != "")
            {
                //插入用户增加的部门名称

                DbHelperSQL.ExecuteSql(strsql.ToString());

                //显示所有的部门名称
                BindGridView();

                //清空文本框中的内容

                txbDepartment.Text = "";
            }
            else
            {
                JS.Alert("部门名称不能为空!请输入部门名称!");
            }
        }
        catch (Exception ex)
        {
            JS.Alert("操作失败,详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
        }
    }


    #region 绑定GridView1
    protected void BindGridView()
    {
        if (!JS.isCookiesAvailabile())
        {
            return;
        }

        try
        {
            DataTable dt = DbHelperSQL.gettable("SELECT * FROM DICT_DEPARTMENT WHERE DEPARTMENTID>0");
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            JS.Alert("操作失败,详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
        }
    }
    #endregion

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindGridView();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindGridView();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string departmentname = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txbDepartment")).Text.Trim();
        if (!string.IsNullOrEmpty(departmentname))
        {
            StringBuilder strsql = new StringBuilder("UPDATE DICT_DEPARTMENT SET DEPARTMENTNAME='")
                                   .Append(departmentname)
                                   .Append("'")
                                   .Append(" WHERE DEPARTMENTID='")
                                   .Append(GridView1.DataKeys[e.RowIndex].Value)
                                   .Append("'");

                      try
            {
                DbHelperSQL.ExecuteSql(strsql.ToString());
                GridView1.EditIndex = -1;
                BindGridView();
            }
            catch (Exception ex)
            {
                JS.Alert("修改部门名称失败,详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
            }
        }
        else
        {
            JS.Alert("部门名称不可为空,请重新输入!");
        }
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        StringBuilder strsql = new StringBuilder("DELETE FROM DICT_DEPARTMENT WHERE DEPARTMENTID='")
                               .Append(GridView1.DataKeys[e.RowIndex].Value)
                               .Append("'");

                try
        {
            DbHelperSQL.ExecuteSql(strsql.ToString());
            BindGridView();

        }
        catch (Exception ex)
        {
            JS.Alert("删除部门名称失败!" + ex.Message.Replace("\r\n", "").Replace("'", ""));
        }
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (null == this.GridView1.DataSource)
        {
            return;
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('确定要永久删除该条记录吗?');");

            int index = e.Row.RowIndex;
            if (index >= 0)
            {
                if (this.GridView1.DataSource != null)
                {
                    DataTable dt = ((DataTable)this.GridView1.DataSource);
                    e.Row.Cells[1].Text = "分配权限";
                    e.Row.Cells[1].Attributes.Add("onclick", string.Format("window.open('DepartmentPower.aspx?id={0}','','left=250,top=100,scrollbars=yes,width=700,height=470,resizable=yes');", dt.Rows[e.Row.RowIndex]["DEPARTMENTID"]));

                             }
            }
        }
    }
}
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ManageDepartment .aspx.cs" Inherits="System_ManageDepartment" %>

<!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 id="Head1" runat="server">
    <title>部门管理</title>
    <link href="../css/CRM.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
        <table width="100%" height="100%">
             <tr height="20px">
           <td colspan="3" style="font-weight: bold; font-size: 20px; color: white;  height: 5px;
                    font-family: 楷体_GB2312; height: 27px; background-color: #63769b">
                    部门管理
           </td>
       </tr>
            <tr height="20px">
                <td align="center" style="width: 20%; font-weight: bold; font-size:20px; color:Black; height:5px; font-family: 楷体_GB2312; height:27px;">
                   部门名称:</td>
                <td width="30%">
                    <asp:TextBox ID="txbDepartment" MaxLength="20" Width="300px" Height="20px" runat="server"></asp:TextBox>
                </td>
                <td align="left">
                    &nbsp;<asp:ImageButton ID="ImgDepartment" runat="server" ImageUrl="~/Images/button/btnAdd.gif"
                        OnClick="ImgDepartment_Click" /></td>
            </tr>
            <tr valign="top">
                <td colspan="3">
                    <asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
                    GridLines="None" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing"
                    OnRowUpdating="GridView1_RowUpdating" DataKeyNames="DEPARTMENTID" OnRowCreated="GridView1_RowCreated"
                    OnRowDeleting="GridView1_RowDeleting">
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#EFF3FB" Height="13px" />
                        <EditRowStyle BackColor="#2461BF" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Height="13px" />
                        <AlternatingRowStyle BackColor="White" />
                        <Columns>
                            <asp:TemplateField HeaderText="部门名称" >
                                <EditItemTemplate>
                                    <asp:TextBox ID="txbDepartment" MaxLength="20" runat="server" Text='<%# Eval("DEPARTMENTNAME") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblDepartment" runat="server" Text='<%# Eval("DEPARTMENTNAME") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                             <asp:BoundField  HeaderText="权限">
                                            <HeaderStyle Wrap="False"  />
                                            <ItemStyle Wrap="False" Font-Bold="True" Width="60" ForeColor="MidnightBlue"/>
                                        </asp:BoundField>
                            <%--<asp:HyperLinkField DataNavigateUrlFields="DEPARTMENTID" DataNavigateUrlFormatString="DepartmentPower.aspx?id={0}"
                                 HeaderText="权限" Target="_blank" Text="分配权限" ItemStyle-Width=60>
                                <HeaderStyle Wrap="False" />
                            </asp:HyperLinkField>--%>
                            <asp:CommandField HeaderText="编辑" ShowEditButton="True" ItemStyle-Width=40 />
                            <asp:CommandField HeaderText="删除" ShowDeleteButton="True"  ItemStyle-Width=40/>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>