Friday, April 27, 2007
« www.d385d594-7ee2-49f9-bdc4-35eee98f6e9f... | Main | What is wrong with this? »

I can't tell you how many times I have struggled with where to store a data item in a Check Box control. I typically need to do this when dynamically generating a series of check boxes on a page that correspond to a data item. I have used the tool tip which works ok but exposes your data to the use when the hover over the control. I have seen others manipulate part of the control ID to contain a data item but this seems problematic. Then it came to me:

using System;

 

namespace Utility {

 

    public class CheckBox: System.Web.UI.WebControls.CheckBox {

 

        public CheckBox() { }

 

        public object Data {

            get { return ViewState["Data"]; }

            set { ViewState["Data"] = value; }

        }

    }

}

Download a sample solution.

kick it on DotNetKicks.com   Friday, April 27, 2007 8:59:45 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  |