Thank for your reply!
I created an hashtable, which i use to fill my dropdownlist.
On my form i've got a dropdownlist, 1 button and a textfield.
When i click on the button, all values in my form (textbox and dropdownlist)
are lost!
Keep in mind that everything worked fine on my local machine and viewstate
is enabled.
Your help is much appreciated
Regards,
Ron
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Text Box
TextBox1;
protected System.Web.UI.W ebControls.Butt on Button1;
protected System.Web.UI.W ebControls.Drop DownList
DropDownList1;
private void Page_Load(objec t sender,
System.EventArg s e)
{
if (!IsPostBack)
{
Hashtable myHash = new
Hashtable();
myHash.Add("1", "One");
myHash.Add("2", "Two");
myHash.Add("3", "Three");
myHash.Add("4", "Four");
foreach (DictionaryEntr y
myDE in myHash)
{
ListItem newLi =
new ListItem();
newLi.Text =
myDE.Value.ToSt ring();
newLi.Value =
myDE.Key.ToStri ng();
DropDownList1.I tems.Add(newLi) ;
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the
ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code
editor.
/// </summary>
private void InitializeCompo nent()
{
this.Button1.Cl ick += new
System.EventHan dler(this.Butto n1_Click);
this.Load += new
System.EventHan dler(this.Page_ Load);
}
#endregion
private void Button1_Click(o bject sender,
System.EventArg s e)
{
TextBox1.Text =
DropDownList1.S electedValue;
}
}
}
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
hi
post some code, especially where you define the dropdown in the aspx file
and where you fill it and the load method
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ron Wallegie" <wa******@hotma il.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..I developed a webesite using c#. I have a dropdownlist wich is filled with
database values. When i click on a button on the same page all values are
lost in the dropdownlist.
The most common answer is to populate the ddl in "if !is postback" which
i did. When i debug it seems that before the postback all values are
lost.
When i tried to do the same on my local machine (localhost) everything
works fine.
Can someone please help
regards
Ron