473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Retrieving value of a custom tag

RSH
I am testing a few concepts in preparation of a project. One of the
concepts revolves around a custom dropdownlist class. Basically I am
overriding the RenderContents and writing a custom value called
"CustomTestValue" in each option tag. I am wiring up the
OnSelectedIndexChanged to a Generic OnSelectedIndexChanged event handler.
My question is...Is it possible to get at the value of my custom value
during postback? And if so how?

Thanks!
Ron
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim liCol As ListItemCollection

Dim item As ListItem

liCol = New ListItemCollection

For i As Integer = 1 To 23

item = New ListItem

item.Text = i

item.Value = i

liCol.Add(item)

Next

Dim DDL As New CustomDDL(liCol)

DDL.AutoPostBack = True

AddHandler DDL.SelectedIndexChanged, AddressOf DDL_SelectedIndexChanged

PlaceHolder1.Controls.Add(DDL)

End Sub

Private Sub DDL_SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs)

Label1.Text = sender.SelectedItem.Text

sender.selecteditem.text = sender.selecteditem.text

End Sub

End Class

Public Class CustomDDL

Inherits DropDownList

Sub New(ByVal liCol As ListItemCollection)

For Each item As ListItem In liCol

Dim li As New ListItem

li.Text = item.Text

li.Value = item.Value

Me.Items.Add(li)

Next

End Sub

Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)

Me.Style.Add("Border", "5px")

For Each li As ListItem In Me.Items

If InStr(li.Text, "1") 0 Then

writer.WriteLine("<option class='gray' ")

Else

writer.WriteLine("<option class='black' ")

End If

writer.WriteAttribute("value", li.Value.ToString())

writer.WriteAttribute("CustomTestValue", "TestValue" & li.Value.ToString())

writer.Write(HtmlTextWriter.TagRightChar)

writer.Write(li.Text & " - Modified")

writer.WriteLine("</option>")

writer.WriteLine()

Next

End Sub

End Class
Jan 3 '07 #1
1 1283
RSH
How would I go about implementing that?

I have a few situations where it would be handly to store several different
values with the DropDownList options. Previously I was just creating a
listItem Value that comprised of a delimited string
(value='DivisionID--DepartmentID--LocationID--EmployeeID') and I would
perform a split on the returned value. But if I could include this type of
functionality in a class then i figured this would be a cleaner
implementation.

The other thing I was attempting to do was create a modified ListItem Class
but the ListItem class is un-inheritable.

Any suggestions would be greatly appreciated.

Thanks,
Ron
"Milosz Skalecki [MCAD]" <mi*****@REMOVEITwp.plwrote in message
news:CF**********************************@microsof t.com...
Hi there,

Every class that implements IAttributeAccessor interface allow programatic
access to its attributes (ListItem implements this interface). May i ask
you
how are you going to use it?

--
Milosz
"RSH" wrote:
>I am testing a few concepts in preparation of a project. One of the
concepts revolves around a custom dropdownlist class. Basically I am
overriding the RenderContents and writing a custom value called
"CustomTestValue" in each option tag. I am wiring up the
OnSelectedIndexChanged to a Generic OnSelectedIndexChanged event handler.
My question is...Is it possible to get at the value of my custom value
during postback? And if so how?

Thanks!
Ron
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim liCol As ListItemCollection

Dim item As ListItem

liCol = New ListItemCollection

For i As Integer = 1 To 23

item = New ListItem

item.Text = i

item.Value = i

liCol.Add(item)

Next

Dim DDL As New CustomDDL(liCol)

DDL.AutoPostBack = True

AddHandler DDL.SelectedIndexChanged, AddressOf DDL_SelectedIndexChanged

PlaceHolder1.Controls.Add(DDL)

End Sub

Private Sub DDL_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e
As System.EventArgs)

Label1.Text = sender.SelectedItem.Text

sender.selecteditem.text = sender.selecteditem.text

End Sub

End Class

Public Class CustomDDL

Inherits DropDownList

Sub New(ByVal liCol As ListItemCollection)

For Each item As ListItem In liCol

Dim li As New ListItem

li.Text = item.Text

li.Value = item.Value

Me.Items.Add(li)

Next

End Sub

Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)

Me.Style.Add("Border", "5px")

For Each li As ListItem In Me.Items

If InStr(li.Text, "1") 0 Then

writer.WriteLine("<option class='gray' ")

Else

writer.WriteLine("<option class='black' ")

End If

writer.WriteAttribute("value", li.Value.ToString())

writer.WriteAttribute("CustomTestValue", "TestValue" &
li.Value.ToString())

writer.Write(HtmlTextWriter.TagRightChar)

writer.Write(li.Text & " - Modified")

writer.WriteLine("</option>")

writer.WriteLine()

Next

End Sub

End Class

Jan 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave | last post by:
Hello. I want to create some custom settings in my Web.config file and then retrieve it in my application, exactly I want to store some connection string for my database. I'm adding these...
1
by: kevininstructor | last post by:
I added a custom section from code found on the Internet and can not get it to work in DotNet 1.1 In the configuration file below my focus is on the "TestGroup" section, all other parts work...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
1
by: Captain Dondo | last post by:
I am not really experienced in Javascript so bear with me.... I am working with an embedded platform; no mouse, no keyboard. Just up, down, left, right keys and +/- keys for...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.