| | |
User Control
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 62
Reputation:
Solved Threads: 4
I am creating a user control in ASP.NET 2.0 that includes a DropDownList. Does anyone know how to get the collection of ListItems that are hard coded between the opening and closing tags of my custom control into the DropDownList inside my user control? I feel like I should know this already.
Here's the error I'm currently getting.
Type 'ASP.form_controls_udropdownlist_ascx' does not have a public property named 'ListItem'.
Thanks!
Here's the error I'm currently getting.
Type 'ASP.form_controls_udropdownlist_ascx' does not have a public property named 'ListItem'.
Thanks!
Last edited by a496761; Feb 18th, 2008 at 5:15 pm.
•
•
Join Date: Feb 2008
Posts: 62
Reputation:
Solved Threads: 4
I'm trying to make a custom user control which has the same functionality as a DropDownList, except with a few extra properties. Basically I'm making a set of dummied-down controls that our designers will easily be able to implement (and will have the required properties for a custom, centralized form processor). Here's a quick example of what I did for the textbox.
.ascx.vb (the .ascx file contains nothing but a textbox with ID=txt_field)
So they can implement this control as follows:
I want to do the same thing for the DropDownList, RadioButtonList etc., but I'm not sure how to handle the listitems. Does that make it more clear? Thanks a lot!
.ascx.vb (the .ascx file contains nothing but a textbox with ID=txt_field)
ASP.NET Syntax (Toggle Plain Text)
Partial Class form_controls_uTextBox Inherits System.Web.UI.UserControl #Region "Privates" Private int_columns As Integer = 0 Private int_max_length As Integer = 0 Private str_textmode As String = "SingleLine" Private str_label As String = "" #End Region #Region "Event Handlers" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If int_columns > 0 Then txt_field.Columns = int_columns If int_max_length > 0 Then txt_field.MaxLength = int_max_length If str_textmode <> "SingleLine" Then txt_field.TextMode = str_textmode End Sub #End Region #Region "Properties" Public Property Columns() As Integer Get Return int_columns End Get Set(ByVal value As Integer) int_columns = value End Set End Property Public Property MaxLength() As Integer Get Return int_max_length End Get Set(ByVal value As Integer) int_max_length = value End Set End Property Public Property TextMode() As String Get Return str_textmode End Get Set(ByVal value As String) If value = "MultiLine" Or value = "Password" Then str_textmode = value End If End Set End Property Public Property Label() As String Get Return str_label End Get Set(ByVal value As String) str_label = value End Set End Property #End Region #Region "Readonly Properties" Public ReadOnly Property Text() As String Get Return txt_field.Text End Get End Property #End Region End Class
So they can implement this control as follows:
ASP.NET Syntax (Toggle Plain Text)
<tr><td>Test TextBox</td><td><uc1:uTextBox ID="uTextBox1" runat="server" Columns="100" Label="Test TextBox" runat="server" /></td></tr>
I want to do the same thing for the DropDownList, RadioButtonList etc., but I'm not sure how to handle the listitems. Does that make it more clear? Thanks a lot!
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
yes it makes things much more clear. I have never created my own control, so no idea on that part. However, I don't think it would be that difficult.
First things first. Are you going to be using different values for DataFieldValue and DataFieldText? If so, it makes it a bit more complicated for practical designers. However, if not, then you can have them do a comma deliminated field and have that value turned into an array with the split method. Then with the split method, loop through to pump out the information.
Example:
However, if you wish to have differences, then do something like this:
Like I said, I haven't created my own controls yet, but I know what I am doing when it comes to making life a bit easier lol. I made myself a 200+ line code file that makes binding controls and sorting through data a cinch. I can bind a datalist control with the following code:
First things first. Are you going to be using different values for DataFieldValue and DataFieldText? If so, it makes it a bit more complicated for practical designers. However, if not, then you can have them do a comma deliminated field and have that value turned into an array with the split method. Then with the split method, loop through to pump out the information.
Example:
ASP.NET Syntax (Toggle Plain Text)
ListItems="Happy Hour, Money Tuesdays, Thursdays, Fridays Are the Best" Function GetItems(ByVal li As String) As String Dim ListItems() As String = li.split(",") For Each Item in ListItems GetItems &= "<option value=""" & Trim(Item) & """>" & Trim(Item) & "</option>" Next End Function
ASP.NET Syntax (Toggle Plain Text)
ListItems = "haphour: HappyHour, money: Money Tuesdays, thu: Thursdays, fribest: Fridays Are the Best" Function GetItems(ByVal li As String) As String Dim ListItems() As String = li.split(",") Dim ListItemsSub() As String For Each Item In ListItems ListItemsSub() = Item.split(":") GetItems &= "<option value=""" & Trim(ListItemsSub(0)) & """>" & Trim(ListItemsSub(1)) & "</option>" Next End Function
ASP.NET Syntax (Toggle Plain Text)
'Bind datalist: TryConn() SetCmd(....) 'handles sql and ALL parameters. TryReader() AssignReader(datalistname) CloseReader() CloseConn() Finalize() ' does all closing and everything just in case I forget a close reader or conn command. 'Commence large update or insert: TryConn() SetCmd(....) ExecNonQuery() CloseConn()
![]() |
Similar Threads
- ASP.NET wizard control (ASP.NET)
- How to register page for a web user control codebehind?? (ASP.NET)
- User Control (ASP.NET)
- New textbox in user control broke datagrid sorting (ASP.NET)
- help...Creation of Drag and drop user control which should be used dynamically (ASP.NET)
- User Control Panel not working (DaniWeb Community Feedback)
- How to set User control=false (ASP.NET)
- get width of windows user control in inches (C#)
- Exception when trying to use a ActiveX control (VB.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Asp compilation error
- Next Thread: RequiredFieldValidator AND ContentPlaceHolderID
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 ajax alltypeofvideos appliances application asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class complex control countryselector dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit editing embeddingactivexcontrol feedback fileuploader fill findcontrol flash folder form gridview gudi iis image javascript languages list listbox maps mobile mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols parent problem profile project radio redirect registration relationaldatabases reportemail response.redirect richtextbox rows schoolproject search security select sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview validatedate validation vb.net videos vista visualstudio vs2008 web webapplications webdevelopment webprogramming wizard xsl







Unfortunately, I can't get any of the designers on board with this format so I'm still trying to figure out a way to use hard-coded ListItems. Anyone have any ideas? Thanks again!
ropDownList with multiple asp:ListItems as child controls and they want to keep that format (can't teach old dogs new tricks I guess).