The Artima Developer Community
Sponsored Link

.NET Buzz Forum
A Simple Alphabet Select List

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brendan Tompkins

Posts: 158
Nickname: brendant
Registered: Apr, 2005

Brendan Tompkins is .NET Developer and founder of CodeBetter.Com
A Simple Alphabet Select List Posted: Nov 10, 2005 9:45 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Brendan Tompkins.
Original Post: A Simple Alphabet Select List
Feed Title: Brendan Tompkins
Feed URL: /error.htm?aspxerrorpath=/blogs/brendan.tompkins/Rss.aspx
Feed Description: Blog First. Ask Questions Later.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Brendan Tompkins
Latest Posts From Brendan Tompkins

Advertisement

Recently, I decided that our user administration pages here at work for our public website was due for an overhaul.   The old version had become very painful to work with indeed, since depended on a categorized tree view of all of our registered companies and users on our public web site, it looked sorta like this:

Our membership is in the thousands now, and the tree view paradigm has completely become unusable with this amount of data. In fact the HTML page size alone for this page was nearly a megabyte!  Ack!   I think there’s some UI rule here about tree views and expected data size, but I had to find a better way.   After some experimentation, the new design allows the admin to group the company list by alphabet.  The new design looks like this, and works much better. Total page size is under 150K now.  Not great, I know, but a vast improvement.  And for the small user population that uses this, it'll do fine for a while ;) .

Anyhow, the alphabet selection control I thought may be something that will see some re-use, so I’ve implemented it as a simple custom control that can be dragged onto a web form.  It supports one event, ItemSelected, and has one property SelectedItem.  The idea is very simple, and chances are this has been done over and over again by many, but I thought I’d share this snippet of code here:

Good Luck!

-Brendan

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

 

namespace YourNamespace.Web.UI.WebControls

{

 

    [DefaultEvent("ItemSelected")]

    public class AlphabetList : System.Web.UI.WebControls.WebControl

    {       

        public event System.EventHandler ItemSelected;

 

        protected override void OnInit(EventArgs e)

        {

            for(int i=65; i < 91; i++)

            {

                LinkButton lb = new LinkButton();

                string alphaChar = ((char)i).ToString();

                lb.Text = alphaChar;

                lb.CommandArgument = alphaChar;

                lb.Click += new EventHandler(lb_Click);

                lb.ID = alphaChar;

                this.Controls.Add(lb);

                this.Controls.Add(new LiteralControl("&nbsp;"));

            }

 

            LinkButton lbAll = new LinkButton();

            lbAll.Text = "ALL";

            lbAll.CommandArgument = "ALL";

            lbAll.Click += new EventHandler(lb_Click);

            lbAll.ID = "ALL";

            this.Controls.Add(lbAll);

 

            base.OnInit(e);

 

        }

 

        /// <summary>

        /// Gets the selected item.

        /// </summary>

        /// <value>The selected item.</value>

        public string SelectedItem

        {

            get

            {

                return this.ViewState["selected"] as string;   

            }

        }

 

        /// <summary>

        /// Handles the Click event of the lb control.

        /// </summary>

        /// <param name="sender">The source of the event.</param>

        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>

        private void lb_Click(object sender, EventArgs e)

        {

            if(this.SelectedItem != null)

            {

                (this.FindControl(this.SelectedItem) as LinkButton).Enabled = true;

            }

 

            this.ViewState["selected"] = (sender as LinkButton).CommandArgument;

            (sender as LinkButton).Enabled = false;

 

            if(this.ItemSelected != null)

                this.ItemSelected(this, new EventArgs());

        }

    }

}

Read: A Simple Alphabet Select List

Topic: More Telerik goodness Previous Topic   Next Topic Topic: Windows Live Favorites

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use