471,580 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,580 software developers and data experts.

Adding additional properties to list items in a dropDownlist through inheritance

RSH
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
Jan 2 '07 #1
1 3070
"RSH" <wa*************@yahoo.comwrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...
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 <selectHTML tag,
and the various <optionelements 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.

<asp:DropDownList 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];
}
Jan 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Shiju Poyilil | last post: by
3 posts views Thread by Stephen Adam | last post: by
5 posts views Thread by Mike | last post: by
1 post views Thread by mitchman10 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.