• GridView实现的请假申请(列表、主键、编辑等常用事件)


    一、页面代码:

    View Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="askforleave.aspx.cs" Inherits="Web.oa.askforleave" %>

    <!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>
    <script src="../js/dateTimePicker.js" type="text/javascript"></script>
    <script src="../js/rili.js" type="text/javascript"></script>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:Panel ID="plList" runat="server">
    <asp:Button ID="btLeave" runat="server" Text="请假" onclick="btLeave_Click" />
    <asp:GridView ID="gvLeave" runat="server" AllowPaging="True"
    AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="F_LeaveID"
    EnableModelValidation="True" onsorting="gvLeave_Sorting">
    <Columns>
    <asp:TemplateField HeaderText="申请人" SortExpression="F_ApplicantID">
    <EditItemTemplate>
    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("F_Name") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# Bind("F_Name") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="开始时间" SortExpression="F_StartTime">
    <EditItemTemplate>
    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("F_StartTime","{0:d}") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label2" runat="server" Text='<%# Eval("F_StartTime","{0:d}") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="结束时间" SortExpression="F_EndTime">
    <EditItemTemplate>
    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("F_EndTime","{0:d}") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label3" runat="server" Text='<%# Eval("F_EndTime","{0:d}") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="标题" SortExpression="F_Title">
    <EditItemTemplate>
    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("F_Title") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label4" runat="server" Text='<%# Bind("F_Title") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="状态" SortExpression="F_State">
    <EditItemTemplate>
    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Convert.ToInt32(Eval("F_State"))==0?"未审核":Convert.ToInt32(Eval("F_State"))==1?"通过":"未通过" %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label5" runat="server" Text='<%# Convert.ToInt32(Eval("F_State"))==0?"未审核":Convert.ToInt32(Eval("F_State"))==1?"通过":"未通过" %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="操作">
    <ItemTemplate>
    <asp:ImageButton ID="ibEdit" runat="server" CommandArgument="<%#Container.DataItemIndex %>"
    ImageUrl="~/images/bianji.gif" onclick="ibEdit_Click" />
    <asp:ImageButton ID="ibOpen" runat="server" CommandArgument="<%#Container.DataItemIndex %>"
    ImageUrl="~/images/chakan.gif" onclick="ibOpen_Click" />
    <asp:ImageButton ID="ibDel" runat="server"
    CommandArgument="<%#Container.DataItemIndex %>" onclientclick="return confirm('确认删除?')"
    ImageUrl="~/images/shanchu.gif" onclick="ibDel_Click" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <EmptyDataTemplate>
    没有数据
    </EmptyDataTemplate>
    </asp:GridView>
    </asp:Panel>
    <asp:Panel ID="plAdd" runat="server">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100" height="30">申请人:</td>
    <td width="15">&nbsp;</td>
    <td>
    <asp:Label ID="lbName" runat="server"></asp:Label>
    </td>
    </tr>
    <tr>
    <td height="30">时间:</td>
    <td>&nbsp;</td>
    <td>
    <asp:TextBox ID="txStart" runat="server"></asp:TextBox>
    —<asp:TextBox ID="txEnd" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td height="30">标题:</td>
    <td>&nbsp;</td>
    <td>
    <asp:TextBox ID="txTitle" runat="server" Height="19px" Width="148px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>内容:</td>
    <td>&nbsp;</td>
    <td>
    <asp:TextBox ID="txContent" runat="server" Height="121px" TextMode="MultiLine"
    Width="303px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td height="30">&nbsp;</td>
    <td>&nbsp;</td>
    <td>
    <asp:Button ID="btShenqing" runat="server" Text="申请"
    onclick="btShenqing_Click" />
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </asp:Panel>
    <asp:Panel ID="plEdit" runat="server">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100" height="30">申请人:</td>
    <td width="15">&nbsp;</td>
    <td>
    <asp:Label ID="lbeName" runat="server"></asp:Label>
    </td>
    </tr>
    <tr>
    <td height="30">时间:</td>
    <td>&nbsp;</td>
    <td>
    <asp:TextBox ID="txeStart" runat="server"></asp:TextBox>
    —<asp:TextBox ID="txeEnd" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td height="30">标题:</td>
    <td>&nbsp;</td>
    <td>
    <asp:TextBox ID="txeTitle" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>内容:</td>
    <td>&nbsp;</td>
    <td>
    <asp:TextBox ID="txeContent" runat="server" Height="121px" TextMode="MultiLine"
    Width="303px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td height="30">&nbsp;</td>
    <td>&nbsp;</td>
    <td>
    <asp:Label ID="lbKeyID" runat="server" Visible ="false"></asp:Label>
    <asp:Button ID="bteSubmit" runat="server" Text="编辑" onclick="bteSubmit_Click" />
    </td>
    </tr>
    </table>
    </asp:Panel>
    <asp:Panel ID="plOpen" runat="server">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100" height="30">申请人:</td>
    <td width="15">&nbsp;</td>
    <td>
    <asp:Label ID="lboName" runat="server"></asp:Label>
    </td>
    </tr>
    <tr>
    <td height="30">时间:</td>
    <td>&nbsp;</td>
    <td>
    <asp:Label ID="lbStart" runat="server"></asp:Label>
    —<asp:Label ID="lbEnd" runat="server"></asp:Label>
    </td>
    </tr>
    <tr>
    <td height="30">标题:</td>
    <td>&nbsp;</td>
    <td>
    <asp:Label ID="lbTitle" runat="server"></asp:Label>
    </td>
    </tr>
    <tr>
    <td height="30">内容:</td>
    <td>&nbsp;</td>
    <td><asp:Label ID="lbContent" runat="server"></asp:Label></td>
    </tr>
    <tr>
    <td height="30">审核人:</td>
    <td>&nbsp;</td>
    <td><asp:Label ID="lbAuditorName" runat="server"></asp:Label></td>
    </tr>
    <tr>
    <td height="30">审核状态:</td>
    <td>&nbsp;</td>
    <td><asp:Label ID="lbState" runat="server"></asp:Label></td>
    </tr>
    <tr>
    <td height="30">批语:</td>
    <td>&nbsp;</td>
    <td>
    <asp:TextBox ID="txPiyu" runat="server" Height="121px"
    TextMode="MultiLine" Width="303px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td height="30">&nbsp;
    </td>
    <td>&nbsp;
    </td>
    <td>
    <asp:Label ID="lbaKeyID" runat="server" Visible="false"></asp:Label>
    <asp:Button ID="btAuditor" runat="server" Text="审核通过"
    onclick="btAuditor_Click" />&nbsp;
    <asp:Button ID="btAuditorFail" runat="server" Text="审核失败"
    onclick="btAuditorFail_Click" />&nbsp;
    <asp:Button ID="btAuditorCancel" runat="server" Text="取消"
    onclick="btAuditorCancel_Click" />
    </td>
    </tr>
    </table>
    </asp:Panel>
    <asp:Label ID="lbMessage" runat="server" Text="" ForeColor="Red"></asp:Label>
    </form>
    </body>
    </html>

    二、后台代码(因为是项目里的代码,所以设计业务和数据处理的代码就不能贴出来了

    1、Page_Load事件

    View Code
     protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    txStart.Attributes.Add("onfocus", "javascript:HS_setDate(this)");
    txEnd.Attributes.Add("onfocus", "javascript:HS_setDate(this)");
    txeStart.Attributes.Add("onfocus", "javascript:HS_setDate(this)");
    txeEnd.Attributes.Add("onfocus", "javascript:HS_setDate(this)");
    if (configcompany != null)
    {
    LeaveBind(configcompany.CompanyID);
    plList.Visible = true;
    plAdd.Visible = false;
    plEdit.Visible = false;
    plOpen.Visible = false;
    }
    }
    }

    2、LeaveBind(GridView数据绑定)

    View Code
    protected void LeaveBind(int id)
    {
    // 获取GridView排序数据列及排序方向
    string sortExpression = this.gvLeave.Attributes["SortExpression"];
    string sortDirection = this.gvLeave.Attributes["SortDirection"];
    DataTable dt = Mis.GetUserInfo.ReadAskForLeave(id,1);
    // 根据GridView排序数据列及排序方向设置显示的默认数据视图
    if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
    {
    dt.DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
    }
    // GridView绑定并显示数据
    this.gvLeave.DataSource = dt;
    this.gvLeave.DataBind();
    //用户名,密码
    string strName = Mis.GetUserInfo.ReadEmployeeName();
    lbName.Text = strName.ToString();
    lbeName.Text = strName.ToString();
    }

    3、其他的事件代码

    View Code
  • 相关阅读:
    JS连接数据库“实例”
    sql数据字典
    硬件防火墙的配置
    xxx
    rhs属性文件删除法
    思科pix防火墙配置实例大全
    SilverLight中的画刷小结
    数据库表间的连接总结
    导入Excel到Sql Server 2005 (转)
    关于Silverlight页面跳转的总结
  • 原文地址:https://www.cnblogs.com/shangxia/p/2281760.html
Copyright © 2020-2023  润新知