2.利用AJAX技术实现局部无闪刷新和GridView定时刷新。
HTML语言:定义AJAX的ScriptManager、UpdatePanel、Triggers以及Timer控件。
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
GridView定义同上(2)
</ContentTemplate>
<Triggers> <asp:AsyncPostBackTrigger ControlID="timChoice" EventName="Tick"/>
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="timChoice" runat="server" Interval="1000" OnTick="timChoice_Tick">
</asp:Timer>
C#语句:
protected void Bind() //找出当前用户的订餐记录,显示到GridView
{
string strUserId = Convert.ToString(Session["userID"]);
string strDeptId = Convert.ToString(Session["deptID"]);
//连接数据库
OleDbConnection Conn = new OleDbConnection(connStr);
Conn.Open();
string strSql = "select ID,dinner_rmk,dinner_cnt,class_rmk,rec_tim,iif(dinner_status='00','待确认',iif(dinner_status='01','已确认','不允许')) as dinner_status,dinner_memo from dinner_choice DC,dinner_info DI,dinner_class CR where DC.dinner_id=DI.dinner_id and DC.dinner_class=DI.dinner_class and DC.dinner_class=CR.dinner_class and DC.user_id='" + strUserId + "' and DC.dept_id='" + strDeptId + "' order by DC.rec_tim";
//创建结果集对象
OleDbDataAdapter rs = new OleDbDataAdapter(strSql, Conn);
//数据集合
DataSet ds = new DataSet();
//把rs给了ds
rs.Fill(ds);
//把ds记录集填充到GridView
gvChoice.DataSource = ds.Tables[0].DefaultView;
gvChoice.DataBind();
Conn.Close();
gvColor();
}
protected void timChoice_Tick(object sender, EventArgs e) //定时执行
{ //定时查询出记录
Bind();
}
3.GridView控件输出到Excel文件。
C#语句:
protected void ctExl_Click(object sender, EventArgs e)
{
ToExcel(gvChoice, "Sum"+ System.DateTime.Now.ToShortDateString());
//调用导出函数
}
//输出到Excel
public void ToExcel(System.Web.UI.WebControls.GridView ctl, string FileName)
{
Response.Clear();
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=" + FileName + ".xls");
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
ctl.AllowPaging = false; //关闭分页
BindQuery(); //如果GRIDVIEW分页,必须调用过程刷新记录集
ctl.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
ctl.AllowPaging = true; //启用分页
BindQuery(); //如果GRIDVIEW分页,必须调用过程刷新记录集
}
//必须重载VerifyRenderingInServerForm函数
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
三、订餐审批
利用新型的CheckBoxList、RadioButtonList、Calendar等Web控件实现多条件的数据检索,并且GridView增加了CheckBox控件,可以多选或全选记录进行批量提交,GridView实现了分页显示。如果审批“不允许”,应用ShowModalDialog()函数调用页面窗口,选择备注内容。
1.利用程序语言组成多个条件的查询语句进行检索。
HTML语言:
<asp:CheckBoxList ID="cblDeptId" runat="server" DataSourceID="a1"
DataTextField="dept_nam" DataValueField="dept_id" RepeatColumns="4" RepeatDirection="Horizontal" Width="339px" Height="19px">
</asp:CheckBoxList></td>
<asp:Label ID="Label3" runat="server" Font-Bold="True" Text="状态" Width="20px"></asp:Label></td>
<asp:CheckBoxList ID="cblDinnerStatus" runat="server" DataSourceID="a2" DataTextField="status_rmk" DataValueField="dinner_status" Width="90px">
</asp:CheckBoxList>
<asp:Label ID="Label4" runat="server" Font-Bold="True" Text="范围" Width="19px"></asp:Label>
<asp:RadioButtonList ID="rdlTab" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rdlTab_SelectedIndexChanged"
Width="90px">
<asp:ListItem Selected="True" Value="DAY">当天记录</asp:ListItem>
<asp:ListItem Value="HIS">历史记录</asp:ListItem>
</asp:RadioButtonList>
<asp:CheckBoxList ID="cblDate" runat="server" AutoPostBack="True" Font-Bold="True" OnSelectedIndexChanged="cblDate_SelectedIndexChanged" Width="60px">
<asp:ListItem Value="BegT">开始日期</asp:ListItem>
<asp:ListItem Value="EndT">结束日期</asp:ListItem>
</asp:CheckBoxList>
<asp:ImageButton ID="ibtBegT" runat="server" OnClick="ibtBegT_Click" Width="30px" Height="30px" ImageUrl="~/icon/CALEN.ICO" /><asp:TextBox ID="txtBegT" runat="server" Font-Bold="False" Font-Italic="False" Width="68px"></asp:TextBox><br />
<asp:ImageButton ID="ibtEndT" runat="server" Height="30px" Width="30px" ImageUrl="~/icon/CALEN.ICO" OnClick="ibtEndT_Click" /><asp:TextBox ID="txtEndT" runat="server" Width="68px"></asp:TextBox></td>
<td align="right" style="width: 13992px; height: 28px">
<asp:Calendar ID="cldRecTim" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66" OnSelectionChanged="cldRecTim_SelectionChanged"
ShowGridLines="True" Visible="False" Width="87px">
<SelectedDayStyle
</asp:Calendar>
|