Use ASP. NET to display the daily scheduled events

Source: Internet
Author: User
Christoph Wille Jacky Chen 2002-07-24

On Windows 2000 (or NT) event day, administrators can be said to be the most important sources of information, the reason is that all the events are always there-from success to heavy loss. Since it is so important, if it can be used through the Web, isn't it more abrupt?

Everyone should be familiar with the event generator. In this article, I will explain how to use ASP. NET and. NET Framework sdks to perfectly simulate and list the daily routines. In order for the author to do this, I will first keep the creation of the website's current website.

The original website of this article must be installed on your webserverMicrosoft. NET Framework SDK. At the same time, I also had a certain degree of awareness of the C # program.

Brute Force

We can take advantage of ASP's knowledge to produce a series of events in order to be more rapid and less efficient. (Even a table, although this example is not a table ). The program name contains:Simple. aspx.

<% @Page Language="C#" %> <% @Import Namespace="System.Diagnostics" %> <% EventLog aLog = new EventLog(); aLog.Log = "System"; aLog.MachineName = "."; // Local machine string strImage = ""; // Icon for the event Response.Write("<p>There are " + aLog.Entries.Count + " entries in the System event log.</p>"); foreach (EventLogEntry entry in aLog.Entries) { switch (entry.EntryType) { case EventLogEntryType.Warning: strImage = "warning.png"; break; case EventLogEntryType.Error: strImage = "error.png"; break; default: strImage = "info.png"; break; } Response.Write("&nbsp;|&nbsp;"); Response.Write(entry.TimeGenerated.ToString() + "&nbsp;|&nbsp;"); Response.Write(entry.Source + "&nbsp;|&nbsp;"); Response.Write(entry.EventID.ToString() + "<br>\r\n"); } %> 

The types of Event Logs can be found in the specified time range.System. Diagnostics, It must be placed at the beginning of the website. The opening day is very direct in itself: creating newEventLogObject, specifyingLogAndMachinename("." Is a local machine ). Then we will immediately retrieve the event's daily records.

We useForeachTo complete this task. In order to make it impossible for me to have such a bad idea, I put a correct case in every loan, the listed sequence is the opposite to the general sequence of the operator: the reverse sequence is listed as the most advanced.

Use DataGrid more perfect

There are a lot of new ideas in ASP. NET, especially in the presentation of information, and what's better is that information does not have to come from the information. YesDataGrid Web ControlAlso, the table (GRID) is generated from the data just like its name ). The only requirement for data source must be supportIcollectionInterface-that is, useEventLog.Entries.

The following original values (Speccolsonly. aspxThe usage of DataGrid is so simple:

<% @Page Language="C#" %> <% @Import Namespace="System.Diagnostics" %> <script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e) { EventLog aLog = new EventLog(); aLog.Log = "System"; aLog.MachineName = "."; LogGrid.DataSource = aLog.Entries; LogGrid.DataBind(); } </script> 

The DataGrid controls the future (the next program) to contain only formatted commands, and there are no other commands. Grid usesPage_loadThe event is entered in, so the event day is opened, and then allocated.Entries)As a DataGridDatasourceAdequacy. Pending callDatabindThe data is imported into the table, but we only use the bitwise, as shown in the following example:

This restriction is applied to the DataGrid's standard worker (Speccolsonly. aspxContains the complete program example ):

<form runat="server"> <asp:DataGrid id="LogGrid" runat="server" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" AutoGenerateColumns="false"> <Columns> <asp:BoundColumn HeaderText="TOF" DataField="EntryType" /> <asp:BoundColumn HeaderText="Date/Time" DataField="TimeGenerated"/> <asp:BoundColumn HeaderText="Source" DataField="Source"/> <asp:BoundColumn HeaderText="Event ID" DataField="EventID"/> </Columns> </asp:DataGrid> </form> 

The first step is to setAutogeneratecolumnsThe property is false. In this way, you can avoid displaying all the features automatically. Now we can specify the positions we want.

I used four link locations (link to the data source ),HeadertextWill appear in the current top column, whileDatafieldThe given bitwise is set to the given bitwise.

In the example, I intentionally set the number of locations to a simple one. There are a lot of bit-level memory types, and when you start to use formatting to play the role, for the designer, it can make you "crazy" have a good time! You can find more examples in Quickstart tutorial.

 

Use shard in the DataGrid

In order to complete the work, I use another DataGrid feature, and the DB programming environment should be well-known-segmentation. The best thing about the DataGrid is that it does not use any program, as shown in the following figure:

This time I will make the entire original shardPaging. aspxIn the article, it is convenient to refer:

<% @Page Language="C#" %> <% @Import Namespace="System.Diagnostics" %> <script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e) { BindGrid(); } void LogGrid_Change(Object sender, DataGridPageChangedEventArgs e) { // Set CurrentPageIndex to the page the user clicked. LogGrid.CurrentPageIndex = e.NewPageIndex; // Rebind the data. BindGrid(); } void BindGrid() { EventLog aLog = new EventLog(); aLog.Log = "System"; aLog.MachineName = "."; LogGrid.DataSource = aLog.Entries; LogGrid.DataBind(); } </script> <body bgcolor="#ffffff"> 

The primary changes can be found on the DataGrid Control Panel:

AllowPaging="True" PageSize="10" PagerStyle-Mode="NumericPages" PagerStyle-HorizontalAlign="Right" PagerStyle-NextPageText="Next" PagerStyle-PrevPageText="Prev" OnPageIndexChanged="LogGrid_Change" 

The two most important features are divided into the first and last columns:AllowpagingAndOnpageindexchanged. The first column indicates segmentation, And the last column indicates that an event method will be triggered when it is changed to another region. The other conformances are only experimental.

In this example, we use a collection instead of the information provided by the resource. I am using a simple statement: I just link the information to the grid. In order to achieve better performance, the information will be re-written in this "applet.

Conclusion

The true purpose of today's article is not to completely implement event-based daily failover, but to demonstrate that the use of DataGrid is very many in the same way, it is not limited to the number of buckets on the application program's resource setting. There are many features that can be used. However, it does not mean anything if you want to renew the event on a daily basis, of course, this function cannot be used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.