RE: Retrieving value of a custom tag

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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



.



Relevant Pages

  • Re: Retrieving value of a custom tag
    ... The other thing I was attempting to do was create a modified ListItem Class ... concepts revolves around a custom dropdownlist class. ... Private Sub Page_Load(ByVal sender As System.Object, ... Dim liCol As ListItemCollection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Reordering in ListView again
    ... >> Dim li As ListItem, ... >> End Sub ... >> Public Sub Push ...
    (microsoft.public.vb.general.discussion)
  • Re: help with listview box please!!!
    ... If your code is in the ItemClick event, you should NOT need to define a ... So delete your Dim statement - by declaring a new ... which (since it was not assigned to a listitem using the Set ... Sub xxxx_itemclick ...
    (microsoft.public.vb.general.discussion)
  • Reordering in ListView again
    ... I don't know whether this is at all possible or not, but what I am trying to create is a listview control which the user can reorder the items of. ... Private Sub Form_Click ... Dim li As ListItem, nIndex As Long ...
    (microsoft.public.vb.general.discussion)
  • Retrieving value of a custom tag
    ... concepts revolves around a custom dropdownlist class. ... Private Sub Page_Load(ByVal sender As System.Object, ... Dim liCol As ListItemCollection ... Dim item As ListItem ...
    (microsoft.public.dotnet.framework.aspnet)