R
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
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