Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding additional properties to list items in a dropDownlist through inheritance

Reply
Thread Tools

Adding additional properties to list items in a dropDownlist through inheritance

 
 
RSH
Guest
Posts: n/a
 
      01-02-2007
Hi,

I have a situation where I need to add several "Hidden" properties to list
items in a dropdownlist. By default the DropDownList item has two
properties with regards to the listitems collection, Text and Value. I need
to add a DivisionID, and DepartmentID.

I assumed i could simply override the ListItem class and add the additional
properties. is this in fact the case? If so what would the code look like?

Thanks in advance for any information you can provide.

Ron


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      01-02-2007
"RSH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I have a situation where I need to add several "Hidden" properties to list
> items in a dropdownlist. By default the DropDownList item has two
> properties with regards to the listitems collection, Text and Value.


That's right.

> I need to add a DivisionID, and DepartmentID.


OK.

> I assumed i could simply override the ListItem class and add the
> additional properties. is this in fact the case? If so what would the
> code look like?


Run your web app and navigate to the page with the DropDownList - do a View
Source. The DropDownList webcontrol simply creates the <select> HTML tag,
and the various <option> elements in it. Whereas you could override the
ListItem class in the way you describe by adding additional properties,
ASP.NET would simply ignore them when creating the HTML markup to stream
down to the client.

> Thanks in advance for any information you can provide.


Fortunately, this is quite easy to work around.

<aspropDownList ID="cmbTest" runat="server" />
<asp:Button ID="cmdTest" runat="server" Text="Test" OnClick=cmdTest_Click />

protected void Page_Load(object sender, EventArgs e)
{
ListItem objItem = null;

objItem = new ListItem();
objItem.Value = "1񦶩";
objItem.Text = "One";
cmbTest.Items.Add(objItem);

objItem = new ListItem();
objItem.Value = "4񧱰";
objItem.Text = "Two";
cmbTest.Items.Add(objItem);
}

protected void cmdTest_Click(object sender, EventArgs e)
{
string strValue = cmbTest.SelectedValue.Split('')[0];
string strDivision = cmbTest.SelectedValue.Split('')[1];
string strDepartment = cmbTest.SelectedValue.Split('')[2];
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The properties for the Img1 element do not have the additional RoundedCornersExtender properties. AAaron123 ASP .Net 2 10-07-2009 12:34 PM
Is there any way to append some items to List box, without retrieving all items through AJAX? Anjan Bhowmik ASP .Net 1 02-14-2008 09:02 PM
Looping through CheckBoxList items doesn't pick up selected ones when items were disabled Bart Van Hemelen ASP .Net 2 09-04-2006 08:35 AM
Adding an additional option to a bound dropdown list estafford ASP .Net 2 11-18-2004 10:00 PM
Adding items to listbox through java script then accessing through asp.net Brian Henry ASP .Net 5 08-03-2004 02:10 AM



Advertisments