Announcement

Collapse
No announcement yet.

Dropdownliste Probleme

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dropdownliste Probleme

    Ich hab in eine WebForm zwei Dropdownlisten eingefügt, lese die WErte aus der Datenbank aus per Execute Reader was auch wunderbar funktioniert. Dann habe ich jeweils on Indexchanged prozeduren wo der Selected value in eine Variable geschrieben wird. Allerdings tut die Webform dieses nciht mehr und wählt immer wieder den ersten eintrag in den Listen aus.
    Kann mir hier jemand helfen. Der Code ist unten angegeben.
    <pre>
    private SqlCommand myCommand;
    private SqlConnection myConnection;
    private string SQLstring;
    private string SQLstring2;
    private string SQLstring3;
    private string SQLstring4;
    private string SQLstring5;
    private string SQLstring6;
    private SqlCommand myCommand2;
    private SqlCommand myCommand3;
    private SqlCommand myCommand4;
    private SqlCommand myCommand5;
    private SqlCommand myCommand6;
    private string curcountry;
    private string curinterest;

    private void Page_Load(object sender, System.EventArgs e)
    {
    string strConnectSQL = "SERVER=172.25.178.46;uid=XXX;password=XXX;DATABAS E=Test;";
    myConnection = new SqlConnection(strConnectSQL);
    myConnection.Open();
    SQLstring = "Select c_name FROM countries";
    myCommand = new SqlCommand( SQLstring, myConnection );
    SqlDataReader myReader = myCommand.ExecuteReader();
    CountryList.DataSource = myReader;
    CountryList.DataTextField ="";
    CountryList.DataValueField ="c_name";
    CountryList.DataBind();
    myReader.Close();
    SQLstring2 = "Select i_name FROM interests";
    myCommand2 = new SqlCommand( SQLstring2, myConnection );
    SqlDataReader myReader2 = myCommand2.ExecuteReader();
    InterestsList.DataSource = myReader2;
    InterestsList.DataTextField ="";
    InterestsList.DataValueField ="i_name";
    InterestsList.DataBind();
    myReader2.Close();

    }

    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.CountryList.SelectedIndexChanged += new System.EventHandler(this.CountryList_SelectedIndex Changed);
    this.InterestsList.SelectedIndexChanged += new System.EventHandler(this.InterestsList_SelectedInd exChanged);
    this.eintragen.Click += new System.EventHandler(this.eintragen_Click);
    this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
    private void CountryList_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    curcountry = CountryList.SelectedValue;

    }

    private void InterestsList_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    curinterest = InterestsList.SelectedValue;
    }
    private void eintragen_Click(object sender, System.EventArgs e)
    {
    SmtpMail.SmtpServer = "mail.fsc.net";
    MailMessage mm = new MailMessage();
    mm.From = "[email protected]";
    mm.To = "[email protected]";
    mm.Subject = "RegisterForm";
    mm.Body ="Neuer Eintrag in das Registration Formular:" + System.Environment.NewLine + System.Environment.NewLine
    + last_name.Text + "\t\t" + FamBox.Text + System.Environment.NewLine
    + first_name.Text + " \t\t\t" + NamBox.Text + System.Environment.NewLine
    + phone.Text + "\t\t\t" + TelBox.Text + System.Environment.NewLine
    + address.Text + "\t\t\t" + AddBox.Text + System.Environment.NewLine
    + city.Text + "\t\t\t" + CityBox.Text + System.Environment.NewLine
    + country.Text + "\t\t\t\t" + CountryList.SelectedValue + System.Environment.NewLine
    + interests.Text + "\t\t" + InterestsList.SelectedValue + System.Environment.NewLine
    + Ergebnis.Text + System.Environment.NewLine;
    SmtpMail.Send(mm);
    SQLstring4 ="Select c.country_id from countries c where c.c_name = \'" + curcountry + "\'";
    SQLstring5 ="Select i.interest_id from interests i where i.i_name = \'" + curinterest + "\'";
    myCommand4 = new SqlCommand( SQLstring4, myConnection);
    SqlDataReader myReader3 = myCommand4.ExecuteReader();
    long curcid = 0;
    if (myReader3.Read())
    curcid = myReader3.GetInt64(0);
    myReader3.Close();
    myCommand5 = new SqlCommand( SQLstring5, myConnection);
    SqlDataReader myReader4 = myCommand5.ExecuteReader();
    long curiid = 0;
    if (myReader4.Read())
    curiid = myReader4.GetInt64(0);
    myReader4.Close();
    SQLstring3 ="Insert into customer(last_name,first_name,phone,address,city,c ountry_id,interest_id) values (\'"+FamBox.Text+"\',\'"+NamBox.Text+"\',\'"+TelBo x.Text+"\',\'"+AddBox.Text+"\',\'"+CityBox.Text+"\ '," + curcid + "," + curiid + ")";
    myCommand3 = new SqlCommand( SQLstring3, myConnection );
    myCommand3.ExecuteNonQuery();
    myConnection.Close();
    </pre>
Working...
X