Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Sending dropdownlist items?

Reply
Thread Tools

Sending dropdownlist items?

 
 
agb
Guest
Posts: n/a
 
      08-27-2003
How can I send dropdownlist items to an ascx file AND
how can I get the dropdownlist items from outside of the ascx file

thanksss...



 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      08-28-2003
The trick is to look inside your page to get an instance of the user control.
Then, look inside the user control to get the object (dropdownlist) that you
want to change.

In the code below, I create an instance of the usercontrol that I find in the
page. I create an instance of the dropdownlist that I find in the usercontrol.
After that, you can add the items. The full source code for both the .ascx and
..aspx files are below.

Dim usrcntrl As UserControl
Dim usrDDL As DropDownList
usrcntrl = Page.FindControl("Usrddl1")
usrDDL = usrcntrl.FindControl("dropdownlist1")
usrDDL.Items.Add("Red")
usrDDL.Items.Add("Blue")
usrDDL.Items.Add("Green")

Does this help?

Ken
MVP [ASP.NET]




<%@ Page Language="vb" AutoEventWireup="false" Codebehind="useuserddl.aspx.vb"
Inherits="p733workev.useuserddl"%>
<%@ Register TagPrefix="uc1" TagName="usrddl" Src="usrddl.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>useuserddl</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body ms_positioning="FlowLayout">
<form id="Form1" method="post" runat="server">
<p>
<uc1:usrddl id="Usrddl1" runat="server"></uc1:usrddl></p>
<p>
<asp:button id="Button1" runat="server" text="Fill
DDL"></asp:button></p>
</form>
</body>
</html>



Public Class useuserddl
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

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
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim usrcntrl As UserControl
Dim usrDDL As DropDownList
usrcntrl = Page.FindControl("Usrddl1")
usrDDL = usrcntrl.FindControl("dropdownlist1")
usrDDL.Items.Add("Red")
usrDDL.Items.Add("Blue")
usrDDL.Items.Add("Green")
End Sub
End Class




<%@ Control Language="vb" AutoEventWireup="false" Codebehind="usrddl.ascx.vb"
Inherits="p733workev.usrddl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem value="White">White</asp:listitem>
<asp:listitem value="Black">Black</asp:listitem>
</asp:dropdownlist>



Public Class usrddl
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

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
End Sub

End Class


--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp



"agb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
How can I send dropdownlist items to an ascx file AND
how can I get the dropdownlist items from outside of the ascx file

thanksss...




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem sending mail: Sending the email to the following server failed Luke Java 2 03-15-2007 10:54 AM
pls help me when i sent mail, it vil sending twice instead of once ,am using java.mail,am sending my code.... shailajabtech@gmail.com Java 0 09-28-2006 06:38 AM
GridView: Filtr DropDownList from another DropDownList =?Utf-8?B?SnVhbmpv?= ASP .Net 0 12-23-2005 01:31 PM
databinding a Dropdownlist to another dropdownlist tshad ASP .Net 8 10-19-2005 10:00 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM



Advertisments