WebForm DropDownList never changes! Do I have to implement Event Handler?

G

Guest

Hi Folks

i got a DataBound Drop-Down-List where I want to select some Guids out of
My Problem is, that the SelectedItem.Value of the Drop-Down-Lists does not change
I can select whatever I want, I always get the Value with Index 0

Another Thing that I think is strange is that the Eventhandlers PSF_SelectedIndexChanged() an
Stack_SelectedIndexChanged() are never called

Can anybody help me

Thanks in Advanc

Marti

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
using Personal.Web.UI.WebControls
using Microsoft.ApplicationBlocks.Data
using System.Data.SqlClient;
using System.IO;
using System.Web.Mail;
using Dickenbestimmung

namespace OMA

/// <summary
/// Summary description for RichardsonLucy
/// </summary
public class RichardsonLucy : System.Web.UI.Pag

protected System.Web.UI.WebControls.Label Label1
protected System.Web.UI.WebControls.Button Button1
protected System.Web.UI.WebControls.Label Label2
protected System.Web.UI.WebControls.Label Label3
protected System.Web.UI.WebControls.Label Label4
protected System.Web.UI.WebControls.TextBox Boundary1
protected System.Web.UI.WebControls.Label Label5
protected System.Web.UI.WebControls.TextBox Boundary2
protected System.Web.UI.WebControls.Label Label6
protected System.Web.UI.WebControls.Label Label7
protected System.Web.UI.WebControls.TextBox Steps
protected System.Web.UI.WebControls.Label Label8
protected System.Web.UI.WebControls.TextBox lambda
protected System.Web.UI.WebControls.Label Label9
protected System.Web.UI.WebControls.TextBox nmail
protected System.Web.UI.WebControls.TextBox iterations
protected System.Web.UI.WebControls.TextBox OutputStackName
protected System.Web.UI.WebControls.Label Label10
protected System.Web.UI.WebControls.DropDownList Stack
protected System.Web.UI.WebControls.DropDownList PSF
protected System.Web.UI.WebControls.Label Output
protected System.Web.UI.WebControls.TextBox Boundary3

string connectionString = "Password=......."

private void Page_Load(object sender, System.EventArgs e

// Put user code to initialize the page her
SqlConnection con = new SqlConnection(connectionString)
SqlDataAdapter da = new SqlDataAdapter("Select * From StackData", con)
SqlCommandBuilder MyCB = new SqlCommandBuilder(da)

DataSet ds = new DataSet("StackData")
da.Fill(ds,"StackData")
con.Close()

Stack.DataSource = ds.Tables["StackData"].DefaultView
Stack.DataValueField = "StackID"
Stack.DataTextField = "StackName"

PSF.DataSource = ds.Tables["StackData"].DefaultView
PSF.DataValueField = "StackID"
PSF.DataTextField = "StackName"

Stack.DataBind()
PSF.DataBind()


#region Web Form Designer generated cod
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 modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
{
this.Stack.SelectedIndexChanged += new System.EventHandler(this.Stack_SelectedIndexChanged)
this.PSF.SelectedIndexChanged += new System.EventHandler(this.PSF_SelectedIndexChanged)
this.Button1.Click += new System.EventHandler(this.Button1_Click)
this.Load += new System.EventHandler(this.Page_Load)


#endregio

private void Button1_Click(object sender, System.EventArgs e


String StackID = Stack.SelectedItem.Value.ToString()
String PSFID = PSF.SelectedItem.Value.ToString()
Guid GOutputStack = Guid.NewGuid()

Dickenbestimmung.DataStack.db_to_file(connectionString, StackID,"E:\\Stacks\\"+StackID+".dbl")
Dickenbestimmung.DataStack.db_to_file(connectionString,PSFID,"E:\\Stacks\\"+PSFID+".dbl")

String cmdline = "richardsonlucy " + StackID + " " + GOutputStack.ToString() + " " + PSFID + " " + iterations.Text.ToString() + " " + Boundary1.Text.ToString() + " " + Boundary2.Text.ToString() + " " + Boundary3.Text.ToString() + " " + Steps.Text.ToString() + " " + lambda.Text.ToString();

Dickenbestimmung.DataStack.file_to_db(connectionString,"E:\\Stacks\\"+GOutputStack.ToString(),"Test",GOutputStack.ToString(),System.Web.HttpContext.Current.User.Identity.Name.ToString());

Output.Text = cmdline;

MailMessage objEmail = new MailMessage();
objEmail.To = nmail.Text.ToString();
objEmail.From = "[email protected]";
objEmail.Subject = "Richardson Lucy Entfaltung";
objEmail.Body = cmdline;
objEmail.Priority = MailPriority.Normal;
SmtpMail.SmtpServer = "some";
SmtpMail.Send(objEmail);
}
private void PSF_SelectedIndexChanged(object sender, System.EventArgs e)
{
//Code is never called
}

private void Stack_SelectedIndexChanged(object sender, System.EventArgs e)
{
//Code is never called
}
}
}
 
P

Phil Ruelle

Hi Martin,

You need to add:

if (IsPostBack == false)

around the code that populates your dropdowns, else they'll be reset
everytime and always return the first value.

HTH,
Phil

Hi Folks,

i got a DataBound Drop-Down-List where I want to select some Guids out of.
My Problem is, that the SelectedItem.Value of the Drop-Down-Lists does not change,
I can select whatever I want, I always get the Value with Index 0.

Another Thing that I think is strange is that the Eventhandlers PSF_SelectedIndexChanged() and
Stack_SelectedIndexChanged() are never called!

Can anybody help me?

Thanks in Advance

Martin

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;
using Personal.Web.UI.WebControls;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web.Mail;
using Dickenbestimmung;

namespace OMAS
{
/// <summary>
/// Summary description for RichardsonLucy.
/// </summary>
public class RichardsonLucy : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox Boundary1;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.TextBox Boundary2;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.TextBox Steps;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.TextBox lambda;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.TextBox nmail;
protected System.Web.UI.WebControls.TextBox iterations;
protected System.Web.UI.WebControls.TextBox OutputStackName;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.DropDownList Stack;
protected System.Web.UI.WebControls.DropDownList PSF;
protected System.Web.UI.WebControls.Label Output;
protected System.Web.UI.WebControls.TextBox Boundary3;

string connectionString = "Password=.......";

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter("Select * From StackData", con);
SqlCommandBuilder MyCB = new SqlCommandBuilder(da);

DataSet ds = new DataSet("StackData");
da.Fill(ds,"StackData");
con.Close();

Stack.DataSource = ds.Tables["StackData"].DefaultView;
Stack.DataValueField = "StackID";
Stack.DataTextField = "StackName";

PSF.DataSource = ds.Tables["StackData"].DefaultView;
PSF.DataValueField = "StackID";
PSF.DataTextField = "StackName";

Stack.DataBind();
PSF.DataBind();
}

#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.Stack.SelectedIndexChanged += new System.EventHandler(this.Stack_SelectedIndexChanged);
this.PSF.SelectedIndexChanged += new System.EventHandler(this.PSF_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{

String StackID = Stack.SelectedItem.Value.ToString();
String PSFID = PSF.SelectedItem.Value.ToString();
Guid GOutputStack = Guid.NewGuid();

Dickenbestimmung.DataStack.db_to_file(connectionString, StackID,"E:\\Stacks\\"+StackID+".dbl");
Dickenbestimmung.DataStack.db_to_file(connectionString,PSFID,"E:\\Stacks\\"+PSFID+".dbl");

String cmdline = "richardsonlucy " + StackID + " " + GOutputStack.ToString() + " " + PSFID + " " + iterations.Text.ToString() + " " + Boundary1.Text.ToString() + " " + Boundary2.Text.ToString() + " " + Boundary3.Text.ToString() + " " + Steps.Text.ToString() + " " + lambda.Text.ToString();

Dickenbestimmung.DataStack.file_to_db(connectionString,"E:\\Stacks\\"+GOutputStack.ToString(),"Test",GOutputStack.ToString(),System.Web.HttpContext.Current.User.Identity.Name.ToString());

Output.Text = cmdline;

MailMessage objEmail = new MailMessage();
objEmail.To = nmail.Text.ToString();
objEmail.From = "[email protected]";
objEmail.Subject = "Richardson Lucy Entfaltung";
objEmail.Body = cmdline;
objEmail.Priority = MailPriority.Normal;
SmtpMail.SmtpServer = "some";
SmtpMail.Send(objEmail);
}
private void PSF_SelectedIndexChanged(object sender, System.EventArgs e)
{
//Code is never called
}

private void Stack_SelectedIndexChanged(object sender, System.EventArgs e)
{
//Code is never called
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top