gridview导出excel3,按时间命名,用panel,隐藏分页部分。

本文详细介绍了如何在ASP.NET页面中使用GridView控件,并将其数据导出为Excel表格,包括面板布局、GridView配置、按钮添加及导出前的格式化处理。
 首先要把GridView控件放到panel中


 <asp:Panel ID="Panel1" runat="server" Width="100%">
  <asp:GridView ID="gridview1" runat="server" Width="100%" CellPadding="4" ForeColor="#333333"
  AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" OnRowDeleting="gridview1_RowDeleting"
  OnRowEditing="gridview1_RowEditing" DataKeyNames="sno" OnDataBound="gridview1_DataBound"
  Font-Size="14px">
  <Columns>
  <asp:HyperLinkField DataTextField="sno" HeaderText="学号" DataNavigateUrlFields="sno"
  DataNavigateUrlFormatString="StudentInfo.aspx?id={0}" />
  <asp:BoundField DataField="sname" HeaderText="姓名" />
  <asp:BoundField DataField="ssex" HeaderText="性别" />
  <asp:BoundField DataField="snational" HeaderText="民族" />
  <%--<asp:BoundField DataField="sdegree" HeaderText="学历" />--%>
  <asp:BoundField DataField="spoliticalFace" HeaderText="整治面貌" />
  <asp:BoundField DataField="sphone" HeaderText="电话" />
  <asp:BoundField DataField="semail" HeaderText="E-mail" />
  <asp:BoundField DataField="saddress" HeaderText="住址" />
  <asp:BoundField DataField="sidcard" HeaderText="身份证号" />
  <asp:CommandField HeaderText="编辑" ShowEditButton="True" ButtonType="Image" EditImageUrl="~/Admin/Images/edit.gif" />
  <asp:CommandField HeaderText="删除" ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/Admin/Images/del.gif" />
  </Columns>
  <PagerTemplate>//以下为自定义分页
  <div id="main">
  <table>
  <tr>
  <td style="text-align: left;">
  <div id="info">
  &nbsp;&nbsp;页次:<asp:Label ID="lblPageCurrent" runat="server" Text="1" CssClass="txtInfo"></asp:Label>
  /<asp:Label ID="lblPageCount" runat="server" Text="1"></asp:Label>&nbsp;&nbsp; 共&nbsp;<asp:Label
  ID="lblPageRow" runat="server" Text="1" CssClass="txtInfo"></asp:Label>&nbsp;条记录
  </div>
  </td>
  <td style="text-align: right;">
  <div id="page">
  <asp:LinkButton ID="btnFirst" runat="server" CssClass="link" CommandName="Pager"
  CommandArgument="First" OnCommand="NavigateToPage">[首页]</asp:LinkButton>&nbsp;
  <asp:LinkButton ID="btnPrev" runat="server" CssClass="link" CommandName="Pager" CommandArgument="Prev"
  OnCommand="NavigateToPage">[前一页]</asp:LinkButton>&nbsp;
  <asp:LinkButton ID="btnNext" runat="server" CssClass="link" CommandName="Pager" CommandArgument="Next"
  OnCommand="NavigateToPage">[下一页]</asp:LinkButton>&nbsp;
  <asp:LinkButton ID="btnLast" runat="server" CssClass="link" CommandName="Pager" CommandArgument="Last"
  OnCommand="NavigateToPage">[尾页]</asp:LinkButton>&nbsp;&nbsp;
  </div>
  </td>
  </tr>
  </table>
  </div>
  </PagerTemplate>

再添加一个按钮,用于触发导出事件:


 <asp:LinkButton ID="lbtnexcel" runat="server" Text="导出到Excel" OnClick="lbtnexcel_Click"></asp:LinkButton>

  以上为aspx页面代码,后台代码则是:


 protected void lbtnexcel_Click(object sender, EventArgs e)
  {
  gridview1.BottomPagerRow.Visible = false;//导出到Excel表后,隐藏分页部分
  gridview1.Columns[9].Visible = false;//隐藏“编辑”列
  gridview1.Columns[10].Visible = false;//隐藏“删除”列
  DateTime dt = DateTime.Now;//给导出后的Excel表命名,结合表的用途以及系统时间来命名
  string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();
  /*如导出的表中有某些列为编号、身份证号之类的纯数字字符串,如不进行处理,则导出的数据会默认为数字,例如原字符串"0010"则会变为数字10,字符串"1245787888"则会变为科学计数法1.236+E9,这样便达不到我们想要的结果,所以需要在导出前对相应列添加格式化的数据类型,以下为格式化为字符串型*/
  foreach (GridViewRow dg in this.gridview1.Rows)
  {
  dg.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");
  dg.Cells[5].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");
  dg.Cells[6].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");
  dg.Cells[8].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");
  }
  Response.Clear();
  Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("学生表" + filename, System.Text.Encoding.UTF8) + ".xls");//导出文件命名
  Response.ContentEncoding = System.Text.Encoding.UTF7;//如果设置为"GB2312"则中文字符可能会乱码
  Response.ContentType = "applicationshlnd.xls";
  System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
  System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
  Panel1.RenderControl(oHtmlTextWriter);//Add the Panel into the output Stream.
  Response.Write(oStringWriter.ToString());//Output the stream.
  Response.Flush();
  Response.End();
  }
  //重载VerifyRenderingInServerForm方法,否则运行的时候会出现如下错误提示:“类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内”
  public override void VerifyRenderingInServerForm(Control control)
  {
  //override VerifyRenderingInServerForm

       }

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>员工借调记录管理</title> <link rel="stylesheet" href="../../css/pageshow.css" /> <style> /* 全局样式重置 */ * { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; } body { background-color: #f9fafb; color: #374151; line-height: 1.5; } /* 容器样式 */ .container { width: 100%; max-width: 1600px; margin: 0 auto; padding: 0 16px; padding-top: 24px; padding-bottom: 24px; } /* 标签页样式 */ .tab-container { border-bottom: 1px solid #e5e7eb; margin-bottom: 16px; } .tab-group { width: 100%; max-width: 1400px; display: flex; } .tab-btn { padding: 12px 8px; border-bottom: 2px solid transparent; font-size: 14px; cursor: pointer; background: none; border: none; outline: none; transition: all 0.2s ease; } .tab-active { border-bottom-color: #1677ff; color: #1677ff; font-weight: 500; } .tab-inactive { color: #6b7280; } .tab-inactive:hover { color: #4b5563; } /* 卡片容器样式 */ .card { background-color: #ffffff; padding: 0px; border-radius: 8px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); margin-bottom: 16px; } /* 搜索区域样式 */ .search-group { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; } /* 表单控件样式 */ .form-control { border: 1px solid #d1d5db; border-radius: 6px; padding: 10px 16px; font-size: 14px; transition: all 0.2s ease; } .form-control:focus { outline: none; border-color: #1677ff; box-shadow: 0 0 0 1px #1677ff; } /* 必填项样式 */ .required-field { position: relative; } .required-field::after { content: "*"; color: #ff4d4f; position: absolute; right: -8px; top: 50%; transform: translateY(-50%); } /* 验证失败样式 */ .input-error { border-color: #ff4d4f !important; } .select-wrapper { position: relative; } .input-wrapper { position: relative; } .input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #6b7280; font-size: 14px; pointer-events: none; } .text-input { padding-left: 32px; width: 192px; } .date-input { padding: 8px 12px; } /* 借调原因输入框样式 */ .reason-input { width: 200px; } /* 按钮样式 */ .btn { padding: 8px 16px; border-radius: 6px; font-size: 14px; cursor: pointer; transition: all 0.2s ease; border: 1px solid transparent; } .btn-primary { background-color: #1677ff; color: #ffffff; } .btn-primary:hover { background-color: #0966e2; } .btn-secondary { background-color: #ffffff; border-color: #d1d5db; color: #4b5563; } .btn-secondary:hover { background-color: #f3f4f6; } .btn-green { background-color: #0FC6C2; color: #ffffff; } .btn-green:hover { background-color: #0da8a5; } .btn-export { background-color: #2F80ED; color: #ffffff; width: 84px; } .btn-export:hover { background-color: #2569d1; } .btn-text-warning { color: #faad14; background: none; border: none; padding: 0; font-size: 14px; cursor: pointer; } .btn-text-warning:hover { color: #d48806; } .btn-text-danger { color: #ff4d4f; background: none; border: none; padding: 0; font-size: 14px; cursor: pointer; } .btn-text-danger:hover { color: #d9363e; } .btn-text-green { color: #0FC6C2; background: none; border: none; padding: 0; font-size: 14px; cursor: pointer; } .btn-text-green:hover { color: #0da8a5; } /* 表格样式 */ .gridview { width: 100%; border-collapse: collapse; } .gridview th { padding: 6px 8px; text-align: left; font-size: 12px; font-weight: 500; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; background-color: #f9fafb; } .gridview td { padding: 6px 8px; font-size: 12px; color: #6b7280; white-space: nowrap; } .gridview tr:nth-child(even) { background-color: #f9fafb; } .gridview input[type="datetime-local"], .gridview select, .gridview input[type="text"] { border: 1px solid #d1d5db; border-radius: 6px; padding: 4px 6px; font-size: 12px; } .gridview input[type="datetime-local"]:focus, .gridview select:focus, .gridview input[type="text"]:focus { outline: none; border-color: #1677ff; box-shadow: 0 0 0 1px #1677ff; } /* 自定义样式 */ .small-circle { width: 12px; height: 12px; border-radius: 50%; background-color: #22c55e; display: inline-block; } .absolute-btn { position: absolute; right: 200px; top: 101px; } /* 响应式调整 */ @media (max-width: 1000px) { .search-group { flex-direction: column; align-items: stretch; } .text-input { width: auto; } .reason-input { width: auto; } .absolute-btn { position: static; margin-top: 12px; } .gridview { display: block; overflow-x: auto; } } </style> <script> // 移除借调原因输入框的 required 属性自动验证 // 仅在点击 Submit 按钮时验证 function validateReason(btn) { // 找到当前行的借调原因输入框 const row = btn.closest(&#39;tr&#39;); const reasonInput = row.querySelector(&#39;.reason-input&#39;); // 清除之前的错误样式 reasonInput.classList.remove(&#39;input-error&#39;); // 验证是否为空 if (!reasonInput.value.trim()) { reasonInput.classList.add(&#39;input-error&#39;); alert(&#39;借调原因不能为空,请填写!&#39;); reasonInput.focus(); return false; } return true; } window.onload = function() { // 绑定表格内所有 Submit 按钮的点击事件 const submitBtns = document.querySelectorAll(&#39;#gvLendRecords .btn-text-green&#39;); submitBtns.forEach(btn => { btn.onclick = function() { return validateReason(this); }; }); }; </script> </head> <body> <form id="form1" runat="server"> <div class="container"> <!-- 标签页切换 --> <div class="tab-container"> <div class="tab-group"> <asp:Button ID="btnLendTab" runat="server" Text="Lend Settings" CssClass="tab-btn tab-active" OnClick="btnLendTab_Click" /> <asp:Button ID="btnBorrowTab" runat="server" Text="Borrowing and lending records" CssClass="tab-btn tab-inactive" OnClick="btnBorrowTab_Click" /> </div> </div> <!-- 借出记录面板 --> <asp:Panel ID="pnlLendRecords" runat="server"> <!-- 搜索区域 --> <div class="card"> <div class="search-group"> <div class="select-wrapper"> <asp:DropDownList ID="ddlFactory" runat="server" CssClass="form-control"> <asp:ListItem Text="Dept" Value=""></asp:ListItem> <asp:ListItem Text="AG1" Value="AG1"></asp:ListItem> <asp:ListItem Text="AG2" Value="AG2"></asp:ListItem> <asp:ListItem Text="AG6" Value="AG6"></asp:ListItem> <asp:ListItem Text="AG7" Value="AG7"></asp:ListItem> <asp:ListItem Text="AG8" Value="AG8"></asp:ListItem> <asp:ListItem Text="AG9" Value="AG9"></asp:ListItem> <asp:ListItem Text="AL2" Value="AL2"></asp:ListItem> <asp:ListItem Text="AL5" Value="AL5"></asp:ListItem> <asp:ListItem Text="AL6" Value="AL6"></asp:ListItem> <asp:ListItem Text="AL7" Value="AL7"></asp:ListItem> <asp:ListItem Text="AL8" Value="AL8"></asp:ListItem> <asp:ListItem Text="AL9" Value="AL9"></asp:ListItem> <asp:ListItem Text="L03" Value="L03"></asp:ListItem> <asp:ListItem Text="L08" Value="L08"></asp:ListItem> <asp:ListItem Text="L12" Value="L12"></asp:ListItem> <asp:ListItem Text="L23" Value="L23"></asp:ListItem> <asp:ListItem Text="L33" Value="L33"></asp:ListItem> <asp:ListItem Text="LMC" Value="LMC"></asp:ListItem> </asp:DropDownList> </div> <div class="input-wrapper"> <asp:TextBox ID="txtEmpIdLend" runat="server" Placeholder="Enter the badge" CssClass="form-control text-input"></asp:TextBox> <div class="input-icon"> <i class="fa fa-search"></i> </div> </div> <asp:Button ID="btnSearchLend" runat="server" Text="Search" CssClass="btn btn-primary" OnClick="btnSearchLend_Click" /> <asp:Button ID="btnRefreshLend" runat="server" Text="刷新" Visible="false" CssClass="btn btn-secondary" OnClick="btnRefreshLend_Click" /> <asp:Button ID="btnAddLend" runat="server" Text="+ Batch Addition" CssClass="btn btn-green" OnClick="btnAddLend_Click" /> <asp:Button ID="btnDownload" runat="server" Text="Download Template" Visible="false" CssClass="btn btn-secondary" OnClick="btnDownload_Click" /> <asp:FileUpload ID="FileUp" runat="server" Text="Select file" CssClass="btn btn-secondary" Visible="false"/> <asp:Button ID="btn_ExInto_pass" runat="server" Text="Check" OnClick="btn_ExInto_pass_Click" CssClass="btn btn-secondary" Visible="false"/> <asp:Button ID="btnUpdate" runat="server" Text="Submit" Visible="false" CssClass="btn btn-green absolute-btn" OnClick="btnUpdate_Click" /> </div> </div> <!-- 表格区域 --> <div class="card"> <asp:GridView ID="gvLendRecords" runat="server" AutoGenerateColumns="false" CssClass="gridview" OnRowCommand="gvLendRecords_RowCommand"> <Columns> <asp:BoundField DataField="Id" HeaderText="ID" /> <asp:BoundField DataField="EmployeeName" HeaderText="Name" /> <asp:BoundField DataField="EmployeeId" HeaderText="Badge" /> <asp:BoundField DataField="Workday_ID" HeaderText="Workday_ID" /> <asp:BoundField DataField="dept_code" HeaderText="Dept" /> <asp:TemplateField HeaderText="Borrow Plant"> <ItemTemplate> <asp:TextBox ID="ddlTargetFactory" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Borrow Dept"> <ItemTemplate> <asp:DropDownList ID="ddlTargetDept" runat="server" CssClass="form-control"> <asp:ListItem Text="Dept" Value=""></asp:ListItem> <asp:ListItem Text="AG1" Value="AG1"></asp:ListItem> <asp:ListItem Text="AG2" Value="AG2"></asp:ListItem> <asp:ListItem Text="AG6" Value="AG6"></asp:ListItem> <asp:ListItem Text="AG7" Value="AG7"></asp:ListItem> <asp:ListItem Text="AG8" Value="AG8"></asp:ListItem> <asp:ListItem Text="AG9" Value="AG9"></asp:ListItem> <asp:ListItem Text="AL2" Value="AL2"></asp:ListItem> <asp:ListItem Text="AL5" Value="AL5"></asp:ListItem> <asp:ListItem Text="AL6" Value="AL6"></asp:ListItem> <asp:ListItem Text="AL7" Value="AL7"></asp:ListItem> <asp:ListItem Text="AL8" Value="AL8"></asp:ListItem> <asp:ListItem Text="AL9" Value="AL9"></asp:ListItem> <asp:ListItem Text="L03" Value="L03"></asp:ListItem> <asp:ListItem Text="L08" Value="L08"></asp:ListItem> <asp:ListItem Text="L12" Value="L12"></asp:ListItem> <asp:ListItem Text="L23" Value="L23"></asp:ListItem> <asp:ListItem Text="L33" Value="L33"></asp:ListItem> <asp:ListItem Text="LMC" Value="LMC"></asp:ListItem> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Start Date"> <ItemTemplate> <asp:TextBox ID="txtStartDate" runat="server" type="datetime-local" CssClass="form-control"> </asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="End Date"> <ItemTemplate> <asp:TextBox ID="txtEndDate" runat="server" type="datetime-local" CssClass="form-control"> </asp:TextBox> </ItemTemplate> </asp:TemplateField> <%-- 新增借调原因列(仅点击Submit验证) --%> <asp:TemplateField HeaderText="借调原因<span style=&#39;color: #ff4d4f;&#39;>*</span>"> <ItemTemplate> <div class="required-field"> <asp:TextBox ID="txtLendReason" runat="server" CssClass="form-control reason-input" placeholder="请填写借调原因" maxlength="200"></asp:TextBox> </div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Operation"> <ItemTemplate> <asp:Button ID="btnModify" runat="server" Text="Submit" CssClass="btn-text-green" CommandName="Modify" CommandArgument=&#39;<%# Eval("Id") %>&#39; /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> <div> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CssClass="gridview" DataKeyNames="Dept,Plant" AutoGenerateEditButton="False" AllowPaging="True" PageSize="20" Visible="false" OnPageIndexChanging="GridView2_PageIndexChanging"> <Columns> <asp:BoundField DataField="Plant" HeaderText="Plant" ReadOnly="True" /> <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True"/> <asp:BoundField DataField="Badge" HeaderText="Badge" ReadOnly="True"/> <asp:BoundField DataField="Dept" HeaderText="Dept" ReadOnly="True"/> <asp:BoundField DataField="Borrow Plant" HeaderText="Borrow Plant" ReadOnly="True"/> <asp:BoundField DataField="Borrow Dept" HeaderText="Borrow Dept" ReadOnly="True"/> <asp:BoundField DataField="Start Date" HeaderText="Start Date" ReadOnly="True" DataFormatString="{0:yyyy-MM-dd HH:mm}" HtmlEncode="False"/> <asp:BoundField DataField="End Date" HeaderText="End Date" ReadOnly="True" DataFormatString="{0:yyyy-MM-dd HH:mm}" HtmlEncode="False"/> <%-- 展示借调原因 --%> <asp:BoundField DataField="借调原因" HeaderText="借调原因" ReadOnly="True"/> </Columns> <HeaderStyle Wrap="False" /> </asp:GridView> </div> </asp:Panel> <!-- 借入记录面板 --> <asp:Panel ID="pnlBorrowRecords" runat="server" Visible="false"> <!-- 搜索区域 --> <div class="card"> <div class="search-group"> <div class="select-wrapper"> <asp:DropDownList ID="deptRecord" runat="server" CssClass="form-control"> <asp:ListItem Text="Dept" Value=""></asp:ListItem> <asp:ListItem Text="AG1" Value="AG1"></asp:ListItem> <asp:ListItem Text="AG2" Value="AG2"></asp:ListItem> <asp:ListItem Text="AG6" Value="AG6"></asp:ListItem> <asp:ListItem Text="AG7" Value="AG7"></asp:ListItem> <asp:ListItem Text="AG8" Value="AG8"></asp:ListItem> <asp:ListItem Text="AG9" Value="AG9"></asp:ListItem> <asp:ListItem Text="AL2" Value="AL2"></asp:ListItem> <asp:ListItem Text="AL5" Value="AL5"></asp:ListItem> <asp:ListItem Text="AL6" Value="AL6"></asp:ListItem> <asp:ListItem Text="AL7" Value="AL7"></asp:ListItem> <asp:ListItem Text="AL8" Value="AL8"></asp:ListItem> <asp:ListItem Text="AL9" Value="AL9"></asp:ListItem> <asp:ListItem Text="L03" Value="L03"></asp:ListItem> <asp:ListItem Text="L08" Value="L08"></asp:ListItem> <asp:ListItem Text="L12" Value="L12"></asp:ListItem> <asp:ListItem Text="L23" Value="L23"></asp:ListItem> <asp:ListItem Text="L33" Value="L33"></asp:ListItem> <asp:ListItem Text="LMC" Value="LMC"></asp:ListItem> </asp:DropDownList> </div> <div class="input-wrapper"> <asp:TextBox ID="txtEmpIdBorrow" runat="server" Placeholder="Enter the badge" CssClass="form-control text-input"></asp:TextBox> <div class="input-icon"> <i class="fa fa-search"></i> </div> </div> <asp:TextBox ID="txtStartDe" runat="server" CssClass="form-control date-input" type="date"> </asp:TextBox> <asp:TextBox ID="txtEndtDe" runat="server" CssClass="form-control date-input" type="date"> </asp:TextBox> <asp:Button ID="btnSearchBorrow" runat="server" Text="Search" CssClass="btn btn-primary" OnClick="btnSearchBorrow_Click" /> <asp:Button ID="btnExport" runat="server" Text="Download" CssClass="btn btn-export" OnClick="btnExport_Click" /> </div> </div> <!-- 表格区域 --> <div class="card"> <asp:GridView ID="gvBorrowRecords" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" CssClass="gridview" OnRowEditing="gvBorrowRecords_RowEditing" OnRowCancelingEdit="gvBorrowRecords_RowCancelingEdit" OnRowUpdating="gvBorrowRecords_RowUpdating" OnRowCommand="gvBorrowRecords_RowCommand"> <Columns> <asp:BoundField DataField="Id" HeaderText="ID" ReadOnly="True"/> <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" /> <asp:BoundField DataField="Badge" HeaderText="Badge" ReadOnly="True"/> <asp:BoundField DataField="Plant" HeaderText="Lending Plant" ReadOnly="True"/> <asp:BoundField DataField="Dept" HeaderText="Lending Dept" ReadOnly="True"/> <asp:TemplateField HeaderText="Borrowing Dept"> <ItemTemplate> <asp:Label ID="lblDept_Temp" runat="server" Text=&#39;<%# Bind("Dept_Temp") %>&#39;></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="Dept_Temp" runat="server" Text=&#39;<%# Bind("Dept_Temp") %>&#39; CssClass="form-control"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Start Date"> <ItemTemplate> <asp:Label ID="lblStart_Date" runat="server" Text=&#39;<%# Eval("Start_Date") != DBNull.Value ? string.Format("{0:yyyy-MM-dd HH:mm}", Eval("Start_Date")) : "" %>&#39;></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="Start_Date" runat="server" type="datetime-local" CssClass="form-control" Text=&#39;<%# Eval("Start_Date") != DBNull.Value ? string.Format("{0:yyyy-MM-ddTHH:mm}", Eval("Start_Date")) : "" %>&#39;></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="End Date"> <ItemTemplate> <asp:Label ID="lblFinish_Date" runat="server" Text=&#39;<%# Eval("Finish_Date") != DBNull.Value ? string.Format("{0:yyyy-MM-dd HH:mm}", Eval("Finish_Date")) : "" %>&#39;></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="Finish_Date" runat="server" type="datetime-local" CssClass="form-control" Text=&#39;<%# Eval("Finish_Date") != DBNull.Value ? string.Format("{0:yyyy-MM-ddTHH:mm}", Eval("Finish_Date")) : "" %>&#39;></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Support Date"> <ItemTemplate> <asp:Label ID="lblSupport_Date" runat="server" Text=&#39;<%# Bind("Support_Date") %>&#39;></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="Support_Date" runat="server" Text=&#39;<%# Bind("Support_Date") %>&#39; CssClass="form-control"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Operation"> <ItemTemplate> <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" CssClass="btn-text-warning mr-3"></asp:LinkButton> <asp:Button ID="btnReturn" runat="server" Text="Delete" CssClass="btn-text-danger" CommandName="Return" CommandArgument=&#39;<%# Eval("Id") %>&#39; /> </ItemTemplate> <EditItemTemplate> <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update" Text="Update" CssClass="btn-text-warning mr-2"></asp:LinkButton> <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" CssClass="btn-text-warning mr-1"></asp:LinkButton> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </asp:Panel> </div> </form> </body> </html>优化界面
12-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值