473,396 Members | 1,766 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,396 software developers and data experts.

Dropdownlist selection problems

Can someone please tell my why the following doesn't work!

I don't get any errors on the page but when I choose a value from the
dropdownlist what is ment to happen is that a user control should be loaded
into
the page!

However I don't get any reaction what so ever!

Please see comments below!

Thanks

... code

' loads contol according to the value given to NoMobilePhones()

Public Sub NoMobilePhones(ByVal v_intNoMobilePhoneNumbers As Integer)
Dim iCounter As Integer

If v_intNoMobilePhoneNumbers <> 0 Then
For iCounter = 1 To v_intNoMobilePhoneNumbers

Dim c1 As Control = LoadControl("AddMob.ascx")
AddHere.Controls.Add(c1)
Next
End If
End Sub

'Populates the dropdownlist with numbers 1 - 10
Public Sub PopulateDDLNoMobAccounts()
'assuming you have a button named ForLoop
Dim i As Integer
For i = 1 To 10
v_intNoMobilePhoneNumbers.Items.Add(New ListItem(i.ToString(),
i.ToString()))
Next i
' Adds a "select one" to the dropdownlist
v_intNoMobilePhoneNumbers.Items.Insert(0, New ListItem("Select One",
"0"))
v_intNoMobilePhoneNumbers.SelectedIndex = 0

' This should provide a value to the sub NoMobilePhones()
If i <> 0 Then
Dim NoAccounts As Integer
NoAccounts = CType(v_intNoMobilePhoneNumbers.SelectedItem.Value ,
Integer)
If NoAccounts = 0 Then
lblMobPhone.Text = "Please choose number of Mobile Accounts"
Else
NoMobilePhones(NoAccounts)
End If
End If

End Sub

Nov 19 '05 #1
3 1114
So when is PopulateDDLNoMobAccounts actually called? Because the code itself
works. We tried this in C#:

Control objControl = LoadControl("MyControl.ascx");
this.Controls.Add(objControl);

Kind regards,
Nikander & Margriet Bruggeman

"Tim::.." wrote:
Can someone please tell my why the following doesn't work!

I don't get any errors on the page but when I choose a value from the
dropdownlist what is ment to happen is that a user control should be loaded
into
the page!

However I don't get any reaction what so ever!

Please see comments below!

Thanks

.. code

' loads contol according to the value given to NoMobilePhones()

Public Sub NoMobilePhones(ByVal v_intNoMobilePhoneNumbers As Integer)
Dim iCounter As Integer

If v_intNoMobilePhoneNumbers <> 0 Then
For iCounter = 1 To v_intNoMobilePhoneNumbers

Dim c1 As Control = LoadControl("AddMob.ascx")
AddHere.Controls.Add(c1)
Next
End If
End Sub

'Populates the dropdownlist with numbers 1 - 10
Public Sub PopulateDDLNoMobAccounts()
'assuming you have a button named ForLoop
Dim i As Integer
For i = 1 To 10
v_intNoMobilePhoneNumbers.Items.Add(New ListItem(i.ToString(),
i.ToString()))
Next i
' Adds a "select one" to the dropdownlist
v_intNoMobilePhoneNumbers.Items.Insert(0, New ListItem("Select One",
"0"))
v_intNoMobilePhoneNumbers.SelectedIndex = 0

' This should provide a value to the sub NoMobilePhones()
If i <> 0 Then
Dim NoAccounts As Integer
NoAccounts = CType(v_intNoMobilePhoneNumbers.SelectedItem.Value ,
Integer)
If NoAccounts = 0 Then
lblMobPhone.Text = "Please choose number of Mobile Accounts"
Else
NoMobilePhones(NoAccounts)
End If
End If

End Sub

Nov 19 '05 #2
The PopulateDDLNoMobAccounts is called on page load!

Maybe I have to seperate to sub into two different sub??? What do you think!

Thanks
"Nikander & Margriet Bruggeman" wrote:
So when is PopulateDDLNoMobAccounts actually called? Because the code itself
works. We tried this in C#:

Control objControl = LoadControl("MyControl.ascx");
this.Controls.Add(objControl);

Kind regards,
Nikander & Margriet Bruggeman

"Tim::.." wrote:
Can someone please tell my why the following doesn't work!

I don't get any errors on the page but when I choose a value from the
dropdownlist what is ment to happen is that a user control should be loaded
into
the page!

However I don't get any reaction what so ever!

Please see comments below!

Thanks

.. code

' loads contol according to the value given to NoMobilePhones()

Public Sub NoMobilePhones(ByVal v_intNoMobilePhoneNumbers As Integer)
Dim iCounter As Integer

If v_intNoMobilePhoneNumbers <> 0 Then
For iCounter = 1 To v_intNoMobilePhoneNumbers

Dim c1 As Control = LoadControl("AddMob.ascx")
AddHere.Controls.Add(c1)
Next
End If
End Sub

'Populates the dropdownlist with numbers 1 - 10
Public Sub PopulateDDLNoMobAccounts()
'assuming you have a button named ForLoop
Dim i As Integer
For i = 1 To 10
v_intNoMobilePhoneNumbers.Items.Add(New ListItem(i.ToString(),
i.ToString()))
Next i
' Adds a "select one" to the dropdownlist
v_intNoMobilePhoneNumbers.Items.Insert(0, New ListItem("Select One",
"0"))
v_intNoMobilePhoneNumbers.SelectedIndex = 0

' This should provide a value to the sub NoMobilePhones()
If i <> 0 Then
Dim NoAccounts As Integer
NoAccounts = CType(v_intNoMobilePhoneNumbers.SelectedItem.Value ,
Integer)
If NoAccounts = 0 Then
lblMobPhone.Text = "Please choose number of Mobile Accounts"
Else
NoMobilePhones(NoAccounts)
End If
End If

End Sub

Nov 19 '05 #3
Don't think that would matter. Isn't it more logical to add this code to the
SelectIndexChanged event of the dropdownlist? We've included our test code,
it's C# but maybe it's of use anyway to you.

Kind regards,
Nikander & Margriet Bruggeman

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Ng.LoadControls
{
/// <summary>
/// Summary description for LoadControl.
/// </summary>
public class LoadControl : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
DropDownList1.Items.Add("test");
DropDownList1.Items.Add("test2");
DropDownList1.Items.Add("test3");
//AddControls(3);
}

private void AddControls(int intNumber)
{
for ( int i = 0; i < intNumber; i++ )
{
Control objControl = LoadControl("MyControl.ascx");
this.Controls.Add(objControl);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new
System.EventHandler(this.DropDownList1_SelectedInd exChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
AddControls(10);
}
}
}

"Tim::.." wrote:
The PopulateDDLNoMobAccounts is called on page load!

Maybe I have to seperate to sub into two different sub??? What do you think!

Thanks
"Nikander & Margriet Bruggeman" wrote:
So when is PopulateDDLNoMobAccounts actually called? Because the code itself
works. We tried this in C#:

Control objControl = LoadControl("MyControl.ascx");
this.Controls.Add(objControl);

Kind regards,
Nikander & Margriet Bruggeman

"Tim::.." wrote:
Can someone please tell my why the following doesn't work!

I don't get any errors on the page but when I choose a value from the
dropdownlist what is ment to happen is that a user control should be loaded
into
the page!

However I don't get any reaction what so ever!

Please see comments below!

Thanks

.. code

' loads contol according to the value given to NoMobilePhones()

Public Sub NoMobilePhones(ByVal v_intNoMobilePhoneNumbers As Integer)
Dim iCounter As Integer

If v_intNoMobilePhoneNumbers <> 0 Then
For iCounter = 1 To v_intNoMobilePhoneNumbers

Dim c1 As Control = LoadControl("AddMob.ascx")
AddHere.Controls.Add(c1)
Next
End If
End Sub

'Populates the dropdownlist with numbers 1 - 10
Public Sub PopulateDDLNoMobAccounts()
'assuming you have a button named ForLoop
Dim i As Integer
For i = 1 To 10
v_intNoMobilePhoneNumbers.Items.Add(New ListItem(i.ToString(),
i.ToString()))
Next i
' Adds a "select one" to the dropdownlist
v_intNoMobilePhoneNumbers.Items.Insert(0, New ListItem("Select One",
"0"))
v_intNoMobilePhoneNumbers.SelectedIndex = 0

' This should provide a value to the sub NoMobilePhones()
If i <> 0 Then
Dim NoAccounts As Integer
NoAccounts = CType(v_intNoMobilePhoneNumbers.SelectedItem.Value ,
Integer)
If NoAccounts = 0 Then
lblMobPhone.Text = "Please choose number of Mobile Accounts"
Else
NoMobilePhones(NoAccounts)
End If
End If

End Sub

Nov 19 '05 #4

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

Similar topics

2
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
4
by: Chris Kettenbach | last post by:
Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplate I have a dropdownlist. I know on the itemdatabound event is where I...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
by: =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post by:
Hello, On a webpage, create an UpdatePanel with two DropDownLists. Set AutoPostBack of DropDownList1 to true. In the SelectedIndexChanged method, refill DropDownList2 and set the focus to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.