|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Google Analytics ASP.NET Grid seriesThe Google Analytics ASP.NET Grid Series will show you how to create an ASP.NET grid that recreates the appearance and behavior of the grid displayed in the Google Analytics website.
Read the original article here. IntroductionThe One of the things that seems more interesting about the
Figure 1.
Understanding the DataPager web control and DataPagerFieldWhen you have a huge amount of data, most of the times, you don't want to display all the data at once. For performance and usability issues, it is better to display only a set of records and not all the records at once. The To start using the
Figure 2.
Figure 3.
If you want to use the numeric style to page your data, you need to add <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
If you want to use the next and previous style to page your data, you need to add <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1">
<Fields>
<asp:NextPreviousPagerField />
</Fields>
</asp:DataPager>
The The GooglePagerField: Google Analytics navigation controlNow, we are going to talk about our navigation control, the
Figure 4.
Extending the DataPagerFieldNow is the time to create our Google data pager navigation control. We are not going to extend the public class GooglePagerField : DataPagerField
{
protected override DataPagerField CreateField()
{
}
public override void CreateDataPagers(DataPagerFieldItem container,
int startRowIndex, int maximumRows, int totalRowCount, int fieldIndex)
{
}
public override void HandleEvent(CommandEventArgs e)
{
}
}
CreateField methodReturns an instance of the protected override DataPagerField CreateField()
{
return new GooglePagerField();
}
CreateDataPagers methodCreates the UI for our data pager. This table explains the meaning of the parameters of the
Table 1.
The public override void CreateDataPagers(DataPagerFieldItem container, int startRowIndex,
int maximumRows, int totalRowCount, int fieldIndex)
{
this._startRowIndex = startRowIndex;
this._maximumRows = maximumRows;
this._totalRowCount = totalRowCount;
if (string.IsNullOrEmpty(base.DataPager.QueryStringField))
{
this.CreateDataPagersForCommand(container, fieldIndex);
}
else
{
this.CreateDataPagersForQueryString(container, fieldIndex);
}
}
The private void CreateDataPagersForCommand(DataPagerFieldItem container, int fieldIndex)
{
//Goto item texbox
this.CreateGoToTexBox(container);
//Control used to set the page size.
this.CreatePageSizeControl(container);
//Set of records - total records
this.CreateLabelRecordControl(container);
//Previous button
if (this._showPreviousPage)
{
container.Controls.Add(this.CreateControl("Prev", this.PreviousPageText,
fieldIndex, this.PreviousPageImageUrl, this._showPreviousPage));
this.AddNonBreakingSpace(container);
}
//Next button
if (this._showNextPage)
{
container.Controls.Add(this.CreateControl("Next", this.NextPageText,
fieldIndex, this.NextPageImageUrl, this._showNextPage));
this.AddNonBreakingSpace(container);
}
}
HandleEvent methodHandles the events raised by the objects created in the
public override void HandleEvent(CommandEventArgs e)
{
if (string.Equals(e.CommandName, "UpdatePageSize"))
{
base.DataPager.PageSize = Int32.Parse(e.CommandArgument.ToString());
base.DataPager.SetPageProperties(this._startRowIndex,
base.DataPager.PageSize, true);
return;
}
if (string.Equals(e.CommandName, "GoToItem"))
{
int newStartRowIndex = Int32.Parse(e.CommandArgument.ToString());
base.DataPager.SetPageProperties(newStartRowIndex,
base.DataPager.PageSize, true);
return;
}
if (string.IsNullOrEmpty(base.DataPager.QueryStringField))
{
if (string.Equals(e.CommandName, "Prev"))
{
int startRowIndex = this._startRowIndex - base.DataPager.PageSize;
if (startRowIndex < 0)
{
startRowIndex = 0;
}
base.DataPager.SetPageProperties(startRowIndex,
base.DataPager.PageSize, true);
}
else if (string.Equals(e.CommandName, "Next"))
{
int nextStartRowIndex = this._startRowIndex + base.DataPager.PageSize;
if (nextStartRowIndex > this._totalRowCount)
nextStartRowIndex = this._totalRowCount - base.DataPager.PageSize;
if (nextStartRowIndex < 0)
nextStartRowIndex = 0;
base.DataPager.SetPageProperties(nextStartRowIndex,
base.DataPager.PageSize, true);
}
}
}
ButtonDropDownList web controlThe public class ButtonDropDownList : DropDownList, IPostBackEventHandler
{
}
The void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
this.CommandArgument = "0";
if (base.SelectedItem != null)
this.CommandArgument = this.SelectedItem.Value;
this.RaisePostBackEvent(eventArgument);
}
protected virtual void RaisePostBackEvent(string eventArgument)
{
if (this.CausesValidation)
{
this.Page.Validate(this.ValidationGroup);
}
this.OnCommand(new CommandEventArgs(this.CommandName, this.CommandArgument));
}
protected virtual void OnCommand(CommandEventArgs e)
{
CommandEventHandler handler = (CommandEventHandler)base.Events[EventCommand];
if (handler != null)
{
handler(this, e);
}
//It bubbles the event to the HandleEvent method of the GoogleDataPagerField class.
base.RaiseBubbleEvent(this, e);
}
ButtonTextBox web controlThe public class ButtonTextBox : TextBox, IPostBackEventHandler
{
}
The void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
this.CommandArgument = base.Text;
this.RaisePostBackEvent(eventArgument);
}
Using the GoogleDataPagerFieldTo use the Google data pager in your web applications, you only need to add a <asp:ListView ID="ListView1" runat="server"
DataSourceID="AccessDataSource1" ItemPlaceholderID="itemPlaceHolder">
<LayoutTemplate>
<table class="tableInfo">
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
</tr>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
<tr>
<td colspan="3">
<asp:DataPager ID="DataPager1" runat="server"
PagedControlID="ListView1" PageSize="5" >
<Fields>
<SqlNetFrameworkWebControls:GooglePagerField
NextPageImageUrl="~/Images/button_arrow_right.gif"
PreviousPageImageUrl="~/Images/button_arrow_left.gif" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("PlayerId") %></td>
<td><%# Eval("FirstName") %></td>
<td><%# Eval("LastName") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
ConclusionThe Version history
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||