|
|
|
|
||||||||||||||
ASP.NET : “Paged” DropDownList control
Teemu KeiskiI have in
the last two years developed many, many applications that handle insane amounts
of data. And when thinking about the user, in such cases amounts of data will
sometimes reflect to the user experience negatively. One problem I noticed was
that all kinds of dropdownlists and comboboxes might contains thousands of rows. And in this
article I demonstrate how such user experience can be made better by developing
simple customized DropDownList control that has paging
functionality. Key things
when developing this kind of control:
Usage of the control PagedDDL works like any other data-bound
control in ASP.NET. Paging properties are set as needed and then control is
data-bound. When page is changed, index is set either manually or by calling paging
methods and then control is rebound. <cc1:PagedDDL id=PagedDDL1 runat="server" PageSize="5"></cc1:PagedDDL> <br> <asp:Button ID="btnFirst" Runat=server Text="First" /> <asp:Button ID="btnPrevious" Runat=server Text="Previous" /> <asp:Button ID="btnNext" Runat=server Text="Next" /> <asp:Button ID="btnLast" Runat=server Text="Last" /> private void Page_Load(object sender, System.EventArgs
e) { if(!Page.IsPostBack) { BindDDL(); } } //Test data private void BindDDL() { SortedList sl=new SortedList(); for(int
i=1;i<51;i++) sl.Add(i,i); PagedDDL1.DataSource
= sl; PagedDDL1.DataValueField
="Value"; PagedDDL1.DataTextField
="Key"; PagedDDL1.DataBind();
} private void btnFirst_Click(object sender, System.EventArgs
e) { PagedDDL1.GoToFirstPage(); BindDDL(); } private void btnPrevious_Click(object sender, System.EventArgs
e) { PagedDDL1.GoToPreviousPage(); BindDDL(); } private void btnNext_Click(object sender, System.EventArgs
e) { PagedDDL1.GoToNextPage(); BindDDL(); } private void btnLast_Click(object sender, System.EventArgs
e) { PagedDDL1.GoToLastPage(); BindDDL(); } Conclusion Developing control that implements paging is
pretty simple when PagedDataSource class can be
utilized. With same technique paging can be brought into DataList
or Repeater controls, either included or as external feature, provided by the
application. Drawback with current implementation of PagedDDL is that because paging buttons are not implemented
by the control, it has no way to disable for example button that goes to the
first page when we already are at the first page. Although this could be
developed simply so that DDL either implements those buttons or gets their ID’s
provided as properties and when in control’s lifecycle paging details are known
(OnDataBinding), manages visibility of buttons as
needed. | ||||||||||||||||
| Copyright © 2000-2003 ASPAlliance.com Page Rendered at
12/2/2008 6:14:37 AM |
||||||||||||||||