gridview修改,添加,删除等

转载 2007年10月16日 11:00:00

今天有人问起gridview修改的时候取值的问题,以前在2003里用GATAGRID换到2005后很少用了,今天在网上找一这个的修改,添加,删除等,自己有时间也可以看下

下面的gridview使用到了常用的基本功能:

1 dropdownlist的使用

2 新增行的绑定

3 新增行的修改,添加,删除

4 基本功能的编辑,删除

5 行的颜色改变(如编辑行)

6 girdview中时间的验证功能(如开始时间)

7 不可编辑列,不可编辑单元的设置(如建立日期)

代码中有些隐藏的和多余的部分,大家知道一下。最重要的演示gridview的使用。

代码如下:(数据库部分大家感觉一下,不能什么都弄出来。不好意思了。一般人都可以感觉出来的了) 

 

<%@ Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PeiXunJinXiu.aspx.cs" Inherits="InterFace_RenShi_PeiXunJinXiu" ValidateRequest="false" %>

<!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>
    
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    
<form id="formPeiXunJinXiu" runat="server">
    
<div>
    
<table>
                
<tr>
                    
<td>
                        
<asp:Label ID="LabelStatus" runat="server" Font-Size="10pt" Text="当前状态:"></asp:Label></td>
                    
<td>
                        
<asp:Menu ID="MenuCaidan" runat="server" BackColor="#FFFFC0" DynamicHorizontalOffset="2"
                            Font
-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" OnMenuItemClick="MenuCaidan_MenuItemClick"
                            Orientation
="Horizontal" StaticSubMenuIndent="10px">
                            
<StaticMenuItemStyle Font-Size="10pt" HorizontalPadding="5px" VerticalPadding="2px" />
                            
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
                            
<DynamicMenuStyle BackColor="#FFFBD6" />
                            
<StaticSelectedStyle BackColor="Gold" />
                            
<DynamicSelectedStyle BackColor="#FFCC66" />
                            
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                            
<Items>
                                
<asp:MenuItem Selected="True" Text="人事栏" Value="客户栏"></asp:MenuItem>
                                
<asp:MenuItem Text="培训进修" Value="培训进修"></asp:MenuItem>
                            
</Items>
                            
<StaticItemTemplate>
                                
<%# Eval("Text"%>
                            
</StaticItemTemplate>
                            
<StaticHoverStyle BackColor="#FFC0C0" Font-Overline="False" Font-Underline="True"
                                ForeColor
="White" />
                        
</asp:Menu>
                    
</td>
                
</tr>
            
</table>
            
<table style="border-top-width: 0px">
                
<tr valign="top">
                    
<td style="height: 7px">
                        
<img alt="图象" height="5" src="../../Images/funcLine.JPG" width="933" /></td>
                
</tr>
            
</table>
            
<asp:MultiView ID="MultiViewXinXiGuanLi" runat="server" ActiveViewIndex="0">
                
<asp:View ID="ViewXinXiLan" runat="server">
                    
<table>
                        
<tr>
                            
<td>
                                
<table>
                                    
<tr>
                                        
<td>
                                            
<asp:Image ID="ImageShouYe" runat="server" ImageUrl="~/DatabaseImg/100.jpg" /></td>
                                    
</tr>
                                
</table>
                            
</td>
                            
<td>
                                
<table>
                                    
<tr>
                                        
<td style="width: 99px">
                                            选择类别名称
                                        
</td>
                                        
<td>
                                            条件
                                        
</td>
                                        
<td>
                                            输入要查询的条件值
                                        
</td>
                                    
</tr>
                                    
<tr>
                                        
<td style="width: 99px">
                                            
<asp:DropDownList ID="DropDownListLeiBeiOne" runat="server" Width="100px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:DropDownList ID="DropDownListTiaoJianOne" runat="server" Width="80px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:TextBox ID="TextBoxOne" runat="server" class="smallInput"></asp:TextBox></td>
                                    
</tr>
                                    
<tr>
                                        
<td style="width: 99px">
                                            
<asp:DropDownList ID="DropDownListLeiBeiTwo" runat="server" Width="100px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:DropDownList ID="DropDownListTiaoJianTwo" runat="server" Width="80px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:TextBox ID="TextBoxTwo" runat="server" class="smallInput"></asp:TextBox></td>
                                    
</tr>
                                    
<tr>
                                        
<td style="width: 99px">
                                            
<asp:DropDownList ID="DropDownListLeiBeiThree" runat="server" Width="100px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:DropDownList ID="DropDownListTiaoJianThree" runat="server" Width="80px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:TextBox ID="TextBoxThree" runat="server" class="smallInput"></asp:TextBox></td>
                                    
</tr>
                                    
<tr>
                                        
<td style="width: 99px">
                                            
<asp:DropDownList ID="DropDownListLeiBeiFour" runat="server" Width="100px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:DropDownList ID="DropDownListTiaoJianFour" runat="server" Width="80px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                            
<asp:TextBox ID="TextBoxFour" runat="server" class="smallInput"></asp:TextBox></td>
                                    
</tr>
                                    
<tr>
                                        
<td style="width: 99px">
                                            
<font color="blue">
                                                
<asp:Label ID="Labelchaxunfangshi" runat="server" Text="查询排序方式:"></asp:Label></font></td>
                                        
<td>
                                            
<asp:DropDownList ID="DropDownListPaiXuFangShi" runat="server" BackColor="Transparent"
                                                ForeColor
="Blue" Width="80px">
                                            
</asp:DropDownList></td>
                                        
<td>
                                        
</td>
                                    
</tr>
                                
</table>
                            
</td>
                            
<td style="height: 176px">
                                
<table>
                                    
<tr>
                                        
<td style="height: 50px">
                                            
<asp:Button ID="ButtonTiJianChaXun" runat="server" Height="50px" OnClick="ButtonTiJianChaXun_Click"
                                                Text
="条件查询" /></td>
                                    
</tr>
                                
</table>
                            
</td>
                        
</tr>
                    
</table>
                    
<img alt="图象" height="5" src="../../Images/funcLine.JPG" width="933" /><br />
                    
<table>
                        
<tr>
                            
<td>
                                
<asp:Button ID="ButtonChaKan" runat="server" Font-Size="12pt" OnClick="ButtonTianJia_Click"
                                    Text
="查看" />
                            
</td>
                        
</tr>
                    
</table>
                    
<asp:GridView ID="GridViewXinXiLan" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        CellPadding
="4" DataKeyNames="SN" ForeColor="#333333" GridLines="None" OnPageIndexChanging="GridViewXinXiLan_PageIndexChanging">
                        
<FooterStyle BackColor="#507CD1" Font-Bold="True" Font-Size="Small" ForeColor="White" />
                        
<RowStyle BackColor="#EFF3FB" />
                        
<EditRowStyle BackColor="#2461BF" />
                        
<SelectedRowStyle BackColor="DodgerBlue" Font-Bold="False" ForeColor="#333333" />
                        
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        
<HeaderStyle BackColor="#507CD1" Font-Bold="True" Font-Size="10pt" ForeColor="White" />
                        
<AlternatingRowStyle BackColor="White" />
                        
<Columns>
                            
<asp:TemplateField HeaderText="选择" ShowHeader="False">
                                
<ItemTemplate>
                                    
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"
                                        Text
="选择"></asp:LinkButton>
                                
</ItemTemplate>
                                
<ItemStyle Wrap="False" />
                            
</asp:TemplateField>
                            
<asp:BoundField DataField="建立日期" HeaderText="建立日期">
                                
<ItemStyle Wrap="False" />
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="员工编号" HeaderText="员工编号">
                                
<ItemStyle Wrap="False" />
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="姓名" HeaderText="姓名" NullDisplayText=" ">
                                
<ItemStyle Wrap="False" />
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="性别" HeaderText="性别">
                                
<ItemStyle Wrap="False" />
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="民族" HeaderText="民族" NullDisplayText=" ">
                                
<ItemStyle Wrap="False" />
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="籍贯" HeaderText="籍贯" NullDisplayText=" ">
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="出生日期" HeaderText="出生日期">
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="政治面貌" HeaderText="政治面貌">
                                
<HeaderStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="婚姻状况" HeaderText="婚姻状况" />
                            
<asp:BoundField DataField="学历" HeaderText="学历" />
                            
<asp:BoundField DataField="户口" HeaderText="户口" />
                            
<asp:BoundField DataField="身份证号" HeaderText="身份证号" />
                            
<asp:BoundField DataField="职称" HeaderText="职称" />
                            
<asp:BoundField DataField="所属部门" HeaderText="所属部门" />
                            
<asp:BoundField DataField="岗位" HeaderText="岗位" />
                            
<asp:BoundField DataField="入厂时间" HeaderText="入厂时间" />
                            
<asp:BoundField DataField="转正时间" HeaderText="转正时间" />
                            
<asp:BoundField DataField="合同到期" HeaderText="合同到期" />
                            
<asp:BoundField DataField="用工形式" HeaderText="用工形式" />
                            
<asp:BoundField DataField="档案资料" HeaderText="档案资料" />
                            
<asp:BoundField DataField="工作状态" HeaderText="工作状态" />
                            
<asp:BoundField DataField="是否涉密" HeaderText="是否涉密" />
                            
<asp:BoundField DataField="薪金" HeaderText="薪金" />
                            
<asp:BoundField DataField="电话" HeaderText="电话" />
                            
<asp:BoundField DataField="手机" HeaderText="手机" />
                            
<asp:BoundField DataField="电子邮件" HeaderText="电子邮件" />
                            
<asp:BoundField DataField="QQ号" HeaderText="QQ号" />
                            
<asp:BoundField DataField="经办人" HeaderText="经办人" />
                            
<asp:BoundField DataField="SN" HeaderText="SN" Visible="False" />
                        
</Columns>
                        
<PagerSettings Visible="False" />
                    
</asp:GridView>
                    
&nbsp;
                    
<table>
                        
<tr>
                            
<td>
                                
&nbsp;<asp:LinkButton ID="lnkbtnFirst" runat="server" OnClick="PagerButtonClick">首页</asp:LinkButton>
                                
<asp:LinkButton ID="lnkbtnPre" runat="server" OnClick="PagerButtonClick">上一页</asp:LinkButton>
                                
<asp:LinkButton ID="lnkbtnNext" runat="server" OnClick="PagerButtonClick">下一页</asp:LinkButton>
                                
<asp:LinkButton ID="lnkbtnLast" runat="server" OnClick="PagerButtonClick">尾页</asp:LinkButton>
                                
<asp:Label ID="lblCurrentIndex" runat="server" Text="第?页"></asp:Label>
                                
<asp:Label ID="lblPageCount" runat="server" Text="共?页"></asp:Label>
                                
<asp:Label ID="lblRecordCount" runat="server" Text="记录数"></asp:Label>
                                
<asp:TextBox ID="txtJumpPage" runat="server" Width="24px">1</asp:TextBox>
                                
<asp:LinkButton ID="lnkbtnJumpPage" runat="server" OnClick="lnkbtnJumpPage_Click">跳转</asp:LinkButton></td>
                        
</tr>
                    
</table>
                
</asp:View>
                
<asp:View ID="ViewXiangXiXinXi" runat="server">
                    
<asp:GridView ID="GridViewTianJia" runat="server" AutoGenerateColumns="False" CellPadding="4"
                        ForeColor
="#333333" OnRowDataBound="GridViewTianJia_RowDataBound" OnRowCancelingEdit="GridViewTianJia_RowCancelingEdit" OnRowDeleting="GridViewTianJia_RowDeleting" OnRowEditing="GridViewTianJia_RowEditing" DataKeyNames="SN" OnRowUpdating="GridViewTianJia_RowUpdating">
                        
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        
<Columns>
                            
<asp:BoundField DataField="ID" HeaderText="ID" Visible="False" >
                                
<ItemStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="建立日期" HeaderText="建立日期" ReadOnly="True">
                                
<ItemStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:TemplateField HeaderText="姓名">
                                
<EditItemTemplate>
                                    
<asp:TextBox ID="TextBoxXinMing" runat="server" Text='<%# Bind("姓名") %>' Width="60"></asp:TextBox>
                                
</EditItemTemplate>
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:Label ID="Label2" runat="server" Text='<%# Bind("姓名") %>'></asp:Label>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:TemplateField HeaderText="类型">
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:HiddenField ID="HDLeiXing" runat="server" Value='<%# Eval("类型") %>' />
                                    
<asp:DropDownList ID="DropDownListLeiXing" runat="server" Width="60">
                                    
</asp:DropDownList>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:TemplateField HeaderText="名称">
                                
<EditItemTemplate>
                                    
<asp:TextBox ID="TextBoxMingCheng" runat="server" Text='<%# Bind("名称") %>' Width="60"></asp:TextBox>
                                
</EditItemTemplate>
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:Label ID="Label3" runat="server" Text='<%# Bind("名称") %>'></asp:Label>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:TemplateField HeaderText="开始时间">
                                
<EditItemTemplate>
                                    
<asp:TextBox ID="TextBoxKaiShiShiJian" runat="server" Text='<%# Bind("开始时间") %>' Width="70" CausesValidation="True" ValidationGroup="vgpKaiShiShiJian"></asp:TextBox>
                                    
<asp:RequiredFieldValidator ID="reqFromDate" runat="server" ControlToValidate="TextBoxKaiShiShiJian" ErrorMessage="请输入开始时间" ValidationGroup="vgpKaiShiShiJian" Display="Dynamic"  />
                                    
<asp:CustomValidator ID="CVKaiShiShiJian" runat="server" ErrorMessage="日期格式错误()" ControlToValidate="TextBoxKaiShiShiJian" Display="Dynamic" OnServerValidate="CVKaiShiShiJian_ServerValidate"></asp:CustomValidator>
                                
</EditItemTemplate>
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:Label ID="Label4" runat="server" Text='<%# Bind("开始时间") %>'></asp:Label>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:TemplateField HeaderText="结束时间">
                                
<EditItemTemplate>
                                    
<asp:TextBox ID="TextBoxJieShuShiJian" runat="server" Text='<%# Bind("结束时间") %>' Width="70"></asp:TextBox>
                                
</EditItemTemplate>
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:Label ID="Label5" runat="server" Text='<%# Bind("结束时间") %>'></asp:Label>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:TemplateField HeaderText="取得证书">
                                
<EditItemTemplate>
                                    
<asp:TextBox ID="TextBoxZhengShu" runat="server" Text='<%# Bind("取得证书") %>' Width="60"></asp:TextBox>
                                
</EditItemTemplate>
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:Label ID="Label6" runat="server" Text='<%# Bind("取得证书") %>'></asp:Label>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:TemplateField HeaderText="备注">
                                
<EditItemTemplate>
                                    
<asp:TextBox ID="TextBoxBeiZhu" runat="server" Text='<%# Bind("备注") %>' Width="60"></asp:TextBox>
                                
</EditItemTemplate>
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:Label ID="Label7" runat="server" Text='<%# Bind("备注") %>'></asp:Label>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:BoundField DataField="经办人" HeaderText="经办人" ReadOnly="True" >
                                
<ItemStyle Wrap="False" />
                            
</asp:BoundField>
                            
<asp:BoundField DataField="SN" HeaderText="SN" Visible="False" />
                            
<asp:TemplateField HeaderText="编辑" ShowHeader="False">
                                
<EditItemTemplate>
                                    
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                        Text
="更新"></asp:LinkButton>
                                    
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text
="取消"></asp:LinkButton>
                                
</EditItemTemplate>
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                        Text
="编辑"></asp:LinkButton>&nbsp;
                                
</ItemTemplate>
                            
</asp:TemplateField>
                            
<asp:TemplateField HeaderText="操作" ShowHeader="False">
                                
<ItemStyle Wrap="False" />
                                
<ItemTemplate>
                                    
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete"
                                        Text
="删除"></asp:LinkButton>
                                    
<asp:LinkButton ID="LinkButtonTianJia" runat="server" Visible="False" OnClick="LinkButtonTianJia_Click">添加保存</asp:LinkButton>
                                    
<asp:LinkButton ID="LinkButtonQuXiao" runat="server" OnClick="LinkButtonQuXiao_Click"
                                        Visible
="False">取消</asp:LinkButton>
                                
</ItemTemplate>
                            
</asp:TemplateField>
                        
</Columns>
                        
<RowStyle BackColor="#EFF3FB" />
                        
<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" />
                        
<AlternatingRowStyle BackColor="White" />
                        
<EmptyDataTemplate>
                            建立日期 姓名 类型 名称 开始时间 结束时间 取得证书 备注 经办人
                        
</EmptyDataTemplate>
                    
</asp:GridView>
                    
<asp:Button ID="ButtonXinZen" runat="server" Text="新增" OnClick="ButtonXinZen_Click" />
                    
<asp:Button ID="ButtonBaoCun" runat="server" OnClick="ButtonBaoCun_Click" Text="保存" Visible="False" Enabled="False" />
                    
<asp:Button ID="ButtonQuXiao" runat="server" OnClick="ButtonQuXiao_Click" Text="取消" Visible="False" Enabled="False" />
                    
<asp:Label ID="LabelZhuJian" runat="server" Text="隐藏主键" Visible="False"></asp:Label></asp:View>
     
</asp:MultiView>
     
</div>
    
</form>
</body>
</html>

cs代码:

 

/*----------------------------------------------------------------
// Copyright (C) 2007 // 作者:马如林
// 时间:2007/06/08
// 文件名:

// 文件功能描述:
//                 培训进修信息页面
//                  
// 
// 修改标识:
// 修改描述:
// 
//----------------------------------------------------------------
*/



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.Globalization;
using System.Data.OracleClient;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

using Hhxx.App_Code.DatabaseOperate;
using Hhxx.App_Code.Database;
using Hhxx.App_Code.Common;


public partial class InterFace_RenShi_PeiXunJinXiu : System.Web.UI.Page
{

    
//SELECT 建立日期,员工编号,姓名,性别,民族,籍贯,出生日期,政治面貌,婚姻状况,学历,户口,身份证号,职称,所属部门,岗位,入厂时间,转正时间,合同到期,用工形式,档案资料,工作状态,是否涉密,薪金,电话,手机,电子邮件,QQ号,简介,备注,经办人,SN
    private String querySql = "SELECT 建立日期,员工编号,姓名,性别,民族,籍贯,出生日期,政治面貌,婚姻状况,学历,户口,身份证号,职称,所属部门,岗位,入厂时间,转正时间,合同到期,用工形式,档案资料,工作状态,是否涉密,薪金,电话,手机,电子邮件,QQ号,经办人,SN  FROM renshixinxi ";

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
this.MenuCaidan.Items[0].Enabled = true;
        
this.MenuCaidan.Items[1].Enabled = false;

        
if (!Page.IsPostBack)
        
{

            dropDownListInit();
            
// 初始化默认Gridview的SQL语句
        
            fillGridView(querySql);
        }


        
// gridview 换行控制
        this.GridViewXinXiLan.Attributes.Add("style""word-break:keep-all;word-wrap:normal");
    }


    
/// <summary>
    
/// 点击菜单
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void MenuCaidan_MenuItemClick(object sender, MenuEventArgs e)
    
{
        
switch (MenuCaidan.SelectedItem.Text.Trim())
        
{
            
case "人事栏":
                
{
                    MultiViewXinXiGuanLi.ActiveViewIndex 
= 0;
                    
                    fillGridView(querySql);
                    
break;
                }


            
case "培训进修": MultiViewXinXiGuanLi.ActiveViewIndex = 1;
                
break;

            
defaultbreak;
        }

    }


    
/// <summary>
    
/// 条件查询
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void ButtonTiJianChaXun_Click(object sender, EventArgs e)
    
{
        String strCondition 
= "";
        String strChoose 
= "";

        
if (TextBoxOne.Text.Trim().Length != 0)
        
{
            String tempStr 
= DropDownListTiaoJianOne.SelectedItem.Value;
            
switch (tempStr)
            
{
                
case "包含": strChoose = " LIKE ";
                    
break;
                
case "不包含": strChoose = " NOT LIKE ";
                    
break;
            }


            
if (strCondition.Length == 0)
            
{
                strCondition 
= strCondition + DropDownListLeiBeiOne.SelectedItem.Value + strChoose + "'%" + TextBoxOne.Text.Trim() + "%'";
            }

            
else
            
{
                strCondition 
= strCondition + "AND " + DropDownListLeiBeiOne.SelectedItem.Value + strChoose + "'%" + TextBoxOne.Text.Trim() + "%'";
            }

        }


        
if (TextBoxTwo.Text.Trim().Length != 0)
        
{
            String tempStr 
= DropDownListTiaoJianTwo.SelectedItem.Value;
            
switch (tempStr)
            
{
                
case "包含": strChoose = " LIKE ";
                    
break;
                
case "不包含": strChoose = " NOT LIKE ";
                    
break;
            }


            
if (strCondition.Length == 0)
            
{
                strCondition 
= strCondition + DropDownListLeiBeiTwo.SelectedItem.Value + strChoose + "'%" + TextBoxTwo.Text.Trim() + "%'";
            }

            
else
            
{
                strCondition 
= strCondition + "AND " + DropDownListLeiBeiTwo.SelectedItem.Value + strChoose + "'%" + TextBoxTwo.Text.Trim() + "%'";
            }

        }


        
if (TextBoxThree.Text.Trim().Length != 0)
        
{
            String tempStr 
= DropDownListTiaoJianThree.SelectedItem.Value;
            
switch (tempStr)
            
{
                
case "等于": strChoose = "=";
                    
break;
                
case "大于": strChoose = ">";
                    
break;
                
case "小于": strChoose = "<";
                    
break;
            }


            
if (strCondition.Length == 0)
            
{
                strCondition 
= strCondition + DropDownListLeiBeiThree.SelectedItem.Value + strChoose + TextBoxThree.Text.Trim();
            }

            
else
            
{
                strCondition 
= strCondition + "AND " + DropDownListLeiBeiThree.SelectedItem.Value + strChoose + TextBoxThree.Text.Trim();
            }

        }


        
if (TextBoxFour.Text.Trim().Length != 0)
        
{
            String tempStr 
= DropDownListTiaoJianFour.SelectedItem.Value;
            
switch (tempStr)
            
{
                
case "等于": strChoose = "=";
                    
break;
                
case "大于": strChoose = ">";
                    
break;
                
case "小于": strChoose = "<";
                    
break;
            }

            
if (strCondition.Length == 0)
            
{
                strCondition 
= strCondition + DropDownListLeiBeiFour.SelectedItem.Value + strChoose + TextBoxFour.Text.Trim();
            }

            
else
            
{
                strCondition 
= strCondition + "AND " + DropDownListLeiBeiFour.SelectedItem.Value + strChoose + TextBoxFour.Text.Trim();
            }

        }


        
if (strCondition.Length != 0)
        
{
            strCondition 
= " where " + strCondition;
        }


        strCondition 
= strCondition + " ORDER BY " + DropDownListPaiXuFangShi.SelectedItem.Value.Trim();
        String strSql 
= querySql + strCondition;
        String mQuerySql 
= strSql;
        
// 填充表格
        fillGridView(mQuerySql);
        
// 保存SQL语句
        ViewState["sql"= mQuerySql;
    }



    
/// <summary>
    
/// 初始化DropDownList
    
/// </summary>

    private void dropDownListInit()
    
{

        GetTableInformation getTableInformation 
= new GetTableInformation();

        
// 获取表结构信息
        Hashtable tableInfor = getTableInformation.getTableInfor("renshixinxi");

        
// 移除SN
        tableInfor.Remove("SN");

        
foreach (DictionaryEntry de in tableInfor)
        
{
            String key 
= de.Key.ToString();
            String value 
= de.Value.ToString();

            
switch (value)
            
{
                
case "CHAR":
                    DropDownListLeiBeiOne.Items.Add(key);
                    DropDownListLeiBeiTwo.Items.Add(key);
                    
// 排序方式下拉框添加数据字段
                    DropDownListPaiXuFangShi.Items.Add(key);
                    
break;

                
case "VARCHAR2":
                    DropDownListLeiBeiOne.Items.Add(key);
                    DropDownListLeiBeiTwo.Items.Add(key);
                    
// 排序方式下拉框添加数据字段
                    DropDownListPaiXuFangShi.Items.Add(key);
                    
break;

                
case "NUMBER":
                    DropDownListLeiBeiThree.Items.Add(key);
                    DropDownListLeiBeiFour.Items.Add(key);
                    
// 排序方式下拉框添加数据字段
                    DropDownListPaiXuFangShi.Items.Add(key);
                    
break;
            }


        }


        DropDownListTiaoJianOne.Items.Add(
"包含");
        DropDownListTiaoJianOne.Items.Add(
"不包含");

        DropDownListTiaoJianTwo.Items.Add(
"包含");
        DropDownListTiaoJianTwo.Items.Add(
"不包含");

        DropDownListTiaoJianThree.Items.Add(
"等于");
        DropDownListTiaoJianThree.Items.Add(
"小于");
        DropDownListTiaoJianThree.Items.Add(
"大于");

        DropDownListTiaoJianFour.Items.Add(
"等于");
        DropDownListTiaoJianFour.Items.Add(
"小于");
        DropDownListTiaoJianFour.Items.Add(
"大于");

        
if (DropDownListLeiBeiOne.Items.Count == 0)
        
{
            
this.DropDownListLeiBeiOne.Visible = false;
            
this.DropDownListTiaoJianOne.Visible = false;
            
this.TextBoxOne.Visible = false;

        }


        
if (DropDownListLeiBeiTwo.Items.Count == 0)
        
{
            
this.DropDownListLeiBeiTwo.Visible = false;
            
this.DropDownListTiaoJianTwo.Visible = false;
            
this.TextBoxTwo.Visible = false;

        }


        
if (DropDownListLeiBeiThree.Items.Count == 0)
        
{
            
this.DropDownListLeiBeiThree.Visible = false;
            
this.DropDownListTiaoJianThree.Visible = false;
            
this.TextBoxThree.Visible = false;
        }


        
if (DropDownListLeiBeiFour.Items.Count == 0)
        
{
            
this.DropDownListLeiBeiFour.Visible = false;
            
this.DropDownListTiaoJianFour.Visible = false;
            
this.TextBoxFour.Visible = false;

        }


    }


    
/// <summary>
    
/// 填充GridView
    
/// </summary>

    private void fillGridView(String querySql)
    
{
        DataSet ds 
= new DataSet();
        ds 
= GetData(querySql);

        
// 清空以前的数据源
        GridViewXinXiLan.DataSource = null;

        
// 将ds作为信息栏GridView的数据源
        GridViewXinXiLan.DataSource = ds;

        
// 绑定数据
        GridViewXinXiLan.DataBind();

        
// 分页的相关参数设置
        getRefSet(ds);

        
// 保存数据源 防止丢失 VS的破Bug
        ViewState["GridViewXinXiLan_DataSource"= GridViewXinXiLan.DataSource;
        
// 保存SQL语句
        ViewState["sql"= querySql;
    }



    
/// <summary>
    
/// 填充GridView
    
/// </summary>

    private void fillGridViewTianJia(String querySql)
    
{
        DataSet ds 
= new DataSet();
        ds 
= GetData(querySql);

        
// 清空以前的数据源
        GridViewTianJia.DataSource = null;

        
// 将ds作为信息栏GridView的数据源
        GridViewTianJia.DataSource = ds;

        
// 绑定数据
        GridViewTianJia.DataBind();

        
// 分页的相关参数设置
        getRefSet(ds);

        
// 保存数据源 防止丢失 VS的破Bug
        ViewState["GridViewTianJia_DataSource"= this.GridViewTianJia.DataSource;
        
// 保存SQL语句
        ViewState["sql"= querySql;
        
// gridview 换行控制
        this.GridViewTianJia.Attributes.Add("style""word-break:keep-all;word-wrap:normal");
    }


    
/// <summary>
    
/// 转换SQL查询结果为DataSet
    
/// </summary>
    
/// <returns>ds</returns>

    private DataSet GetData(String querySql)
    
{
        String connStr 
= OracleHelper.DatabaseConnStr;

        
// 创建数据集
        DataSet ds = OracleHelper.ExeSqlForDataSet(connStr, CommandType.Text, querySql, null);

        
return ds;
    }



    
/// <summary>
    
/// 首页,上一页,下一页,尾页公用的点击程序
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void PagerButtonClick(object sender, EventArgs e)
    
{
        
        
// CommandArgument对应该对象在页面初始化后的设定值
        
// 减1 是因为系统默认首页的PageIndex为0,为了符合人们的正常思维而使用
        
// 重新绑定
        GridViewXinXiLan.DataSource = ViewState["GridViewXinXiLan_DataSource"];
        GridViewXinXiLan.PageIndex 
= Convert.ToInt32(((LinkButton)sender).CommandArgument) - 1;
        GridViewXinXiLan.DataBind();
        
// 更新当前页面显示值
        lblCurrentIndex.Text = "第 " + (GridViewXinXiLan.PageIndex + 1).ToString() + " 页";

        
// 更新参数
        lnkbtnPre.CommandArgument = (GridViewXinXiLan.PageIndex == 0 ? "1" : GridViewXinXiLan.PageIndex.ToString());
        lnkbtnNext.CommandArgument 
= (GridViewXinXiLan.PageCount == 1 ? GridViewXinXiLan.PageCount.ToString() : (GridViewXinXiLan.PageIndex + 2).ToString());

    }


    
/// <summary>
    
/// 分页的相关参数设置
    
/// </summary>
    
/// <param name="ds"></param>

    protected void getRefSet(DataSet ds)
    
{
        lblCurrentIndex.Text 
= "第 " + (GridViewXinXiLan.PageIndex + 1).ToString() + " 页";
        lblPageCount.Text 
= "共 " + GridViewXinXiLan.PageCount.ToString() + " 页";
        lblRecordCount.Text 
= "总共 " + ds.Tables[0].Rows.Count.ToString() + " 条";

        
if (ds.Tables[0].Rows.Count == 0)
        
{
            lnkbtnFirst.Visible 
= false;
            lnkbtnPre.Visible 
= false;
            lnkbtnNext.Visible 
= false;
            lnkbtnLast.Visible 
= false;

            lblCurrentIndex.Visible 
= false;
            lblPageCount.Visible 
= false;
            lblRecordCount.Visible 
= false;
            
this.lnkbtnJumpPage.Visible = false;
            
this.txtJumpPage.Visible = false;


        }

        
else if (GridViewXinXiLan.PageCount == 1)
        
{
            lnkbtnFirst.Visible 
= false;
            lnkbtnPre.Visible 
= false;
            lnkbtnNext.Visible 
= false;
            lnkbtnLast.Visible 
= false;
        
        }


        
// 设置LinkButton此时对应的参数
        lnkbtnFirst.CommandArgument = "1";
        lnkbtnPre.CommandArgument 
= (GridViewXinXiLan.PageIndex == 0 ? "1" : GridViewXinXiLan.PageIndex.ToString());
        lnkbtnNext.CommandArgument 
= (GridViewXinXiLan.PageCount == 1 ? GridViewXinXiLan.PageCount.ToString() : (GridViewXinXiLan.PageIndex + 2).ToString());
        lnkbtnLast.CommandArgument 
= GridViewXinXiLan.PageCount.ToString();

    }


    
/// <summary>
    
/// 跳转到指定页面,页面参数由txtJumpPage获取
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void lnkbtnJumpPage_Click(object sender, EventArgs e)
    
{
        
// 减1 是因为系统默认首页的PageIndex为0,为了符合人们的正常思维而使用
        
// 重新绑定
        GridViewXinXiLan.DataSource = ViewState["GridViewXinXiLan_DataSource"];
        GridViewXinXiLan.PageIndex 
= int.Parse(txtJumpPage.Text) - 1;
        GridViewXinXiLan.DataBind();
        
// 更新当前页面显示值
        lblCurrentIndex.Text = "第 " + (GridViewXinXiLan.PageIndex + 1).ToString() + " 页";

        
// 更新参数
        lnkbtnPre.CommandArgument = (GridViewXinXiLan.PageIndex == 0 ? "1" : GridViewXinXiLan.PageIndex.ToString());
        lnkbtnNext.CommandArgument 
= (GridViewXinXiLan.PageCount == 1 ? GridViewXinXiLan.PageCount.ToString() : (GridViewXinXiLan.PageIndex + 2).ToString());
    }


    
/// <summary>
    
/// 解决数据源不能分页的问题
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void GridViewXinXiLan_PageIndexChanging(object sender, GridViewPageEventArgs e)
    
{
        
// 读取数据源 设定显示值 并绑定
        GridViewXinXiLan.DataSource = ViewState["GridViewXinXiLan_DataSource"];
        GridViewXinXiLan.PageIndex 
= e.NewPageIndex;
        GridViewXinXiLan.DataBind();
    }


    
/// <summary>
    
/// 查看按钮
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void ButtonTianJia_Click(object sender, EventArgs e)
    
{
        
if (this.GridViewXinXiLan.SelectedRow != null)
        
{
            
this.MenuCaidan.Items[1].Enabled = true;
            MenuCaidan.Items[
1].Selected = true;
            MultiViewXinXiGuanLi.ActiveViewIndex 
= 1;

            
this.LabelZhuJian.Text = this.GridViewXinXiLan.DataKeys[this.GridViewXinXiLan.SelectedRow.RowIndex][0].ToString(); ;

            
// 初始化默认Gridview的SQL语句
            String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

            fillGridViewTianJia(querySql);

            ButtonChaKan.Visible 
= true;
            ButtonChaKan.Enabled 
= true;
        }

        
else
        
{
            
// 错误信息提示
            String tip = "请选择行!";
            Response.Write(
"<script>alert('" + tip + "')</script>");
        }

    }



    
/// <summary>
    
/// 新增
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void ButtonXinZen_Click(object sender, EventArgs e)
    
{
        
//ButtonBaoCun.Visible = true;
        
//ButtonBaoCun.Enabled = true;

        
//ButtonQuXiao.Visible = true;
        
//ButtonQuXiao.Enabled = true;

        DataSet ds 
= new DataSet();
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        ds 
= GetData(querySql);
        
        
// 清空以前的数据源
        GridViewTianJia.DataSource = null;
        String jlrq 
= DateTime.Now.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);
        String sn 
= System.Guid.NewGuid().ToString().Replace("-""");
        String userName 
= "session";
        ds.Tables[
0].Rows.Add(this.LabelZhuJian.Text, jlrq, "姓名""培训类型""名称", jlrq, jlrq, "取得证书""", userName, sn);
        
// 将ds作为信息栏GridView的数据源
        GridViewTianJia.DataSource = ds;
        
        
// 绑定数据
        GridViewTianJia.DataBind();
        
// gridview 换行控制
        this.GridViewTianJia.Attributes.Add("style""word-break:keep-all;word-wrap:normal");
        
// 编辑的更新
        GridViewTianJia.EditIndex = GridViewTianJia.Rows.Count - 1;
        
// 设置编辑行的颜色
        GridViewTianJia.EditRowStyle.BackColor = System.Drawing.Color.Orange;
        
// 绑定数据
        GridViewTianJia.DataBind();
        GridViewTianJia.Rows[GridViewTianJia.Rows.Count 
- 1].FindControl("LinkButton1").Visible = false;
        
// 编辑的取消
        GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("LinkButton2").Visible = false;
        GridViewTianJia.Rows[GridViewTianJia.Rows.Count 
- 1].FindControl("LinkButtonTianJia").Visible = true;
        GridViewTianJia.Rows[GridViewTianJia.Rows.Count 
- 1].FindControl("LinkButton3").Visible = false;
        GridViewTianJia.Rows[GridViewTianJia.Rows.Count 
- 1].FindControl("LinkButtonQuXiao").Visible = true;
    }


    
/// <summary>
    
/// 数据绑定
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void GridViewTianJia_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
//为DropDownList绑定值
        if (((DropDownList)e.Row.FindControl("DropDownListLeiXing")) != null)
        
{
            DropDownList ddlXL 
= (DropDownList)e.Row.FindControl("DropDownListLeiXing");

            
// 奖惩类型
            String conn = OracleHelper.DatabaseConnStr;
            ddlXL.Items.Clear();
            String queryLeiXing 
= "SELECT 名称 FROM XITONGZIDIAN WHERE ID='03010301' ORDER BY 序号";
            OracleDataReader drLeiXing 
= OracleHelper.ExecuteReader(conn, CommandType.Text, queryLeiXing, null);
            
while (drLeiXing.Read())
            
{
                ddlXL.Items.Add(drLeiXing.GetString(
0).Trim());
            }

            drLeiXing.Close();

            
//ddlXL.SelectedValue = ((HiddenField)e.Row.FindControl("HDLeiXing")).Value.ToString().Trim();
            ddlXL.Items.Remove(((HiddenField)e.Row.FindControl("HDLeiXing")).Value.ToString().Trim());
            ddlXL.Items.Insert(
0, ((HiddenField)e.Row.FindControl("HDLeiXing")).Value.ToString().Trim());
        }

        
//如果是绑定数据行 
        if (e.Row.RowType == DataControlRowType.DataRow)
        
{
            
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            
{
                
//((LinkButton)e.Row.Cells[12].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:"" + e.Row.Cells[1].Text.Trim() + ""吗?')");
                ((LinkButton)e.Row.FindControl("LinkButton3")).Attributes.Add("onclick""javascript:return confirm('你确认要删除:"" + e.Row.Cells[1].Text.Trim() + ""吗?')");
            }

        }
 

    }


    
/// <summary>
    
/// 删除
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void GridViewTianJia_RowDeleting(object sender, GridViewDeleteEventArgs e)
    
{
        String sn 
= GridViewTianJia.DataKeys[e.RowIndex].Values[0].ToString().Trim();

        String delSql 
= "DELETE FROM peixunjinxiu WHERE SN = '" + sn + "'";

        OracleConnection conn 
= new OracleConnection(OracleHelper.DatabaseConnStr);
        conn.Open();
        OracleTransaction trans 
= conn.BeginTransaction(IsolationLevel.ReadCommitted);

        
try
        
{
            OracleHelper.ExecuteNonQuery(trans, CommandType.Text, delSql, 
null);
            trans.Commit();
        }

        
catch (Exception ex)
        
{
            trans.Rollback();
            ex.ToString();
        }

        
finally
        
{
            conn.Close();
        }


        GridViewTianJia.EditIndex 
= -1;
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);
    }


    
/// <summary>
    
/// 取消
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void GridViewTianJia_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    
{

        GridViewTianJia.EditIndex 
= -1;
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);
    }


    
/// <summary>
    
/// 编辑
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void GridViewTianJia_RowEditing(object sender, GridViewEditEventArgs e)
    
{
        GridViewTianJia.EditIndex 
= e.NewEditIndex;

        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);
    }


    
/// <summary>
    
/// 更新
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void GridViewTianJia_RowUpdating(object sender, GridViewUpdateEventArgs e)
    
{

        
// 建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN

        String sqlUpdate 
= "UPDATE peixunjinxiu SET 姓名=:xm,类型=:lx,名称=:mc,开始时间=:kssj,结束时间=:jssj,取得证书=:qdzs,备注=:bz"
                            
+ " WHERE SN=:sn";

        OracleParameter[] parms 
= {
            
new OracleParameter(":xm", OracleType.Char, 20),
            
new OracleParameter(":lx", OracleType.Char, 10),
            
new OracleParameter(":mc", OracleType.VarChar, 255),
            
new OracleParameter(":kssj", OracleType.Char, 10),
            
new OracleParameter(":jssj", OracleType.Char, 10),
            
new OracleParameter(":qdzs", OracleType.VarChar, 255),
            
new OracleParameter(":bz", OracleType.VarChar,1024),
            
new OracleParameter(":sn", OracleType.Char, 32)
          }
;

        parms[
0].Value = ((TextBox)GridViewTianJia.Rows[e.RowIndex].FindControl("TextBoxXinMing")).Text.Trim();
        parms[
1].Value = ((DropDownList)GridViewTianJia.Rows[e.RowIndex].FindControl("DropDownListLeiXing")).SelectedValue.ToString().Trim();
        parms[
2].Value = ((TextBox)GridViewTianJia.Rows[e.RowIndex].FindControl("TextBoxMingCheng")).Text.Trim();
        parms[
3].Value = ((TextBox)GridViewTianJia.Rows[e.RowIndex].FindControl("TextBoxKaiShiShiJian")).Text.Trim();
        parms[
4].Value = ((TextBox)GridViewTianJia.Rows[e.RowIndex].FindControl("TextBoxJieShuShiJian")).Text.Trim();
        parms[
5].Value = ((TextBox)GridViewTianJia.Rows[e.RowIndex].FindControl("TextBoxZhengShu")).Text.Trim();
        parms[
6].Value = ((TextBox)GridViewTianJia.Rows[e.RowIndex].FindControl("TextBoxBeiZhu")).Text.Trim();
        parms[
7].Value =  GridViewTianJia.DataKeys[e.RowIndex].Values[0].ToString().Trim();

        OracleConnection conn 
= new OracleConnection(OracleHelper.DatabaseConnStr);
        conn.Open();
        OracleTransaction trans 
= conn.BeginTransaction(IsolationLevel.ReadCommitted);

        
try
        
{
            OracleHelper.ExecuteNonQuery(trans, CommandType.Text, sqlUpdate, parms);
            trans.Commit();
        }

        
catch (Exception ex)
        
{
            trans.Rollback();
            ex.ToString();
        }

        
finally
        
{
            conn.Close();
        }

        GridViewTianJia.EditIndex 
= -1;
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);
    }


    
/// <summary>
    
/// 保存
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void ButtonBaoCun_Click(object sender, EventArgs e)
    
{
        
// 建立日期,姓名,类型,培训名称,进修名称,开始时间,结束时间,取得证书,备注,经办人,SN
        String sqlInsert = "INSERT INTO peixunjinxiu(ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN) "
                            
+ "VALUES(:id,:jlrq,:xm,:lx,:mc,:kssj,:jssj,:qdzs,:bz,:jbr,:sn)";

        OracleParameter[] parms 
= {
                
new OracleParameter(":id", OracleType.Char, 32),
                
new OracleParameter(":jlrq", OracleType.Char, 10),
                
new OracleParameter(":xm", OracleType.Char, 20),
                
new OracleParameter(":lx", OracleType.Char, 10),
                
new OracleParameter(":mc", OracleType.VarChar, 255),
                
new OracleParameter(":kssj", OracleType.Char, 10),
                
new OracleParameter(":jssj", OracleType.Char, 10),
                
new OracleParameter(":qdzs", OracleType.VarChar, 255),
                
new OracleParameter(":bz", OracleType.VarChar,1024),
                
new OracleParameter(":jbr", OracleType.Char, 20),
                
new OracleParameter(":sn", OracleType.Char, 32)
              }
;
        parms[
0].Value = this.LabelZhuJian.Text.Trim();
        parms[
1].Value = this.GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].Cells[1].Text.ToString().Trim();
        parms[
2].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxXinMing")).Text.Trim();
        parms[
3].Value = ((DropDownList)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("DropDownListLeiXing")).SelectedValue.ToString().Trim();
        parms[
4].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxMingCheng")).Text.Trim();
        parms[
5].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxKaiShiShiJian")).Text.Trim();
        parms[
6].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxJieShuShiJian")).Text.Trim();
        parms[
7].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxZhengShu")).Text.Trim();
        parms[
8].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxBeiZhu")).Text.Trim();
        parms[
9].Value = this.GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].Cells[9].Text.ToString().Trim();
        parms[
10].Value = GridViewTianJia.DataKeys[GridViewTianJia.Rows.Count - 1].Values[0].ToString().Trim();

        OracleConnection conn 
= new OracleConnection(OracleHelper.DatabaseConnStr);
        conn.Open();
        OracleTransaction trans 
= conn.BeginTransaction(IsolationLevel.ReadCommitted);

        
try
        
{
            OracleHelper.ExecuteNonQuery(trans, CommandType.Text, sqlInsert, parms);
            trans.Commit();
        }

        
catch (Exception ex)
        
{
            trans.Rollback();
            ex.ToString();
        }

        
finally
        
{
            conn.Close();
        }


        GridViewTianJia.EditIndex 
= -1;
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);

        ButtonBaoCun.Visible 
= false;
        ButtonBaoCun.Enabled 
= false;

        ButtonQuXiao.Visible 
= false;
        ButtonQuXiao.Enabled 
= false;
    }


    
/// <summary>
    
/// 取消
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void ButtonQuXiao_Click(object sender, EventArgs e)
    
{
        GridViewTianJia.EditIndex 
= -1;
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);

        ButtonBaoCun.Visible 
= false;
        ButtonBaoCun.Enabled 
= false;

        ButtonQuXiao.Visible 
= false;
        ButtonQuXiao.Enabled 
= false;
    }


    
/// <summary>
    
/// 取消
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void LinkButtonQuXiao_Click(object sender, EventArgs e)
    
{
        GridViewTianJia.EditIndex 
= -1;
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);

    }


    
/// <summary>
    
/// 添加保存
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void LinkButtonTianJia_Click(object sender, EventArgs e)
    
{

        
if (Page.IsValid)
        
{
            
//
        }

        
// 建立日期,姓名,类型,培训名称,进修名称,开始时间,结束时间,取得证书,备注,经办人,SN
        String sqlInsert = "INSERT INTO peixunjinxiu(ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN) "
                            
+ "VALUES(:id,:jlrq,:xm,:lx,:mc,:kssj,:jssj,:qdzs,:bz,:jbr,:sn)";

        OracleParameter[] parms 
= {
                
new OracleParameter(":id", OracleType.Char, 32),
                
new OracleParameter(":jlrq", OracleType.Char, 10),
                
new OracleParameter(":xm", OracleType.Char, 20),
                
new OracleParameter(":lx", OracleType.Char, 10),
                
new OracleParameter(":mc", OracleType.VarChar, 255),
                
new OracleParameter(":kssj", OracleType.Char, 10),
                
new OracleParameter(":jssj", OracleType.Char, 10),
                
new OracleParameter(":qdzs", OracleType.VarChar, 255),
                
new OracleParameter(":bz", OracleType.VarChar,1024),
                
new OracleParameter(":jbr", OracleType.Char, 20),
                
new OracleParameter(":sn", OracleType.Char, 32)
              }
;

        parms[
0].Value = this.LabelZhuJian.Text.Trim();
        parms[
1].Value = this.GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].Cells[1].Text.ToString().Trim();
        parms[
2].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxXinMing")).Text.Trim();
        parms[
3].Value = ((DropDownList)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("DropDownListLeiXing")).SelectedValue.ToString().Trim();
        parms[
4].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxMingCheng")).Text.Trim();
        parms[
5].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxKaiShiShiJian")).Text.Trim();
        parms[
6].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxJieShuShiJian")).Text.Trim();
        parms[
7].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxZhengShu")).Text.Trim();
        parms[
8].Value = ((TextBox)GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].FindControl("TextBoxBeiZhu")).Text.Trim();
        parms[
9].Value = this.GridViewTianJia.Rows[GridViewTianJia.Rows.Count - 1].Cells[9].Text.ToString().Trim();
        parms[
10].Value = GridViewTianJia.DataKeys[GridViewTianJia.Rows.Count - 1].Values[0].ToString().Trim();

        OracleConnection conn 
= new OracleConnection(OracleHelper.DatabaseConnStr);
        conn.Open();
        OracleTransaction trans 
= conn.BeginTransaction(IsolationLevel.ReadCommitted);

        
try
        
{
            OracleHelper.ExecuteNonQuery(trans, CommandType.Text, sqlInsert, parms);
            trans.Commit();
        }

        
catch (Exception ex)
        
{
            trans.Rollback();
            ex.ToString();
        }

        
finally
        
{
            conn.Close();
        }


        GridViewTianJia.EditIndex 
= -1;
        
// 初始化默认Gridview的SQL语句
        String querySql = "SELECT ID,建立日期,姓名,类型,名称,开始时间,结束时间,取得证书,备注,经办人,SN FROM peixunjinxiu WHERE  ID='" + this.LabelZhuJian.Text.Trim() + "'";

        fillGridViewTianJia(querySql);
    }


    
/// <summary>
    
/// 时间格式验证
    
/// </summary>
    
/// <param name="source"></param>
    
/// <param name="args"></param>

    protected void CVKaiShiShiJian_ServerValidate(object source, ServerValidateEventArgs args)
    
{
        
try
        
{
            DateTime dt 
= DateTime.Parse(args.Value);
            
// 如果长度不为10则不是合法的日期
            if(args.Value.Trim().Length == 10)
            
{
              
                args.IsValid 
= true;
                
return;
            }

        }

        
catch (Exception) 
        

        }

        args.IsValid 
= false;
    }

 
}

  

GridView中直接新增行、编辑和删除

.aspx "server" ID="btnAdd" Text="新增" OnClick="btnAdd_Click" />    "gv" runat="server" Al...
  • theoldfuture
  • theoldfuture
  • 2016年09月13日 01:24
  • 891

WebForm GridView设置分页,编辑,更新,取消,删除,按钮,以及排序。

数据库: 首先要在GridView上取消掉 自动生成列(根据T-SQL) AutoGenerateColumns="False" 添加BoundField,就是绑定列,设置DataFie...
  • u012997311
  • u012997311
  • 2017年10月31日 15:49
  • 468

ASP.NET中GridView控件删除数据的两种方法

今天在用GridView控件时,发现了一个问题,就是使用GridView控件在删除数据时的问题。接下来我们通过模板列方式和CommandField方式删除某条数据讲解下两者之间的区别。    方式一...
  • jiangfei009003
  • jiangfei009003
  • 2013年07月24日 17:44
  • 2581

GridView动态展示照片,长按删除,支持点击放大,裁剪实现

案列:进入页面,判断网络是否有资源照片,没有则默认展示添加的照片!            点击进行图片相册的选择,这里也可以进行相机的拍照的选取!            对照片进行裁剪,保存后上传...
  • Lucy__
  • Lucy__
  • 2016年11月22日 15:31
  • 948

【转载】gridview修改,添加,删除…

今天有人问起gridview修改的时候取值的问题,以前在2003里用GATAGRID换到2005后很少用了,今天在网上找一这个的修改,添加,删除等,自己有时间也可以看下 下面的gridview使用到...
  • juelingfeng
  • juelingfeng
  • 2014年08月07日 13:22
  • 118

【转载】gridview修改,添加,删除…

cs代码: using System; using System.Data; using System.Configuration; using System.Collections; ...
  • juelingfeng
  • juelingfeng
  • 2014年08月07日 13:22
  • 123

【转载】gridview修改,添加,删除…

///      /// 查看按钮     ///      /// name="sender">     /// name="e">     protected void But...
  • juelingfeng
  • juelingfeng
  • 2014年08月07日 13:22
  • 206

关于ASP.NET中GridView控件中编辑和删除按钮布局问题

ASP.NET中的GridView控件在显示数据方面,使用起来还是比较方便的。如果想在此基础上加入编辑和删除或者修改等操作时为了布局的美观需要改变自动生成的布局。可是并没有相关的属性可以设置自动生成的...
  • wangzl1163
  • wangzl1163
  • 2015年11月03日 16:08
  • 2029

GridView动态进行行添加和删除

出处:http://www.cnblogs.com/shenzhoulong/ gridview动态添加行的原理就是用datatable增加新列然后重新绑定; 设计源码 设计gridview代码...
  • TaiHuangTang
  • TaiHuangTang
  • 2013年10月30日 09:51
  • 546

Android GridView扩展仿微信微博发图动态添加删除图片

在平时的开发中,我们会看到不管是微信发朋友圈照片还是微博发布新鲜事,添加图片的时候都是选完后面还有个+号再去选择图片,这样的话比较方便用户去添加图片,有的右上角还有个-号方便用户去删除图片,而一般用户...
  • u010785585
  • u010785585
  • 2016年11月04日 14:29
  • 4735
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:gridview修改,添加,删除等
举报原因:
原因补充:

(最多只允许输入30个字)