SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP.NEt postback dropdownlist problem

    Hello guys, my code as below, problem is after changes made in my dropdownlist, the value of my dropdownlist isn't changing. I've tried everyting. Please help me out. Thanks!

    Code:
    using System;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using System.Data;
    using System.Diagnostics;
    using Oracle.DataAccess.Client;
    
    namespace WebApplication1
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            public bool connectionStatus;
            private string sLogFormat;
            private string sTime;
            private const string CONNECTIONSTRING_NAME = "OracleConnection";
            string sYear   = DateTime.Now.Year.ToString();
            string sMonth  = DateTime.Now.Month.ToString();
            string sDay    = DateTime.Now.Day.ToString();
            OracleConnection connection = new OracleConnection();
            
             
    
            public void LogFile(string sPathName, string sErrMsg)
            {
                 sLogFormat = DateTime.Now.ToShortDateString().ToString() + DateTime.Now.ToLongTimeString().ToString();
                 sTime = sYear + sMonth + sDay;
    
                 StreamWriter sw = new StreamWriter(sPathName + sTime,true);
                 sw.WriteLine(sLogFormat + sErrMsg);
                 sw.Flush();
                 sw.Close();
            }
    
            public bool GetOracleConnection()          
            {
                connection.ConnectionString = "User Id=GLB_AL_CERBERUS;Password=allcerberus;Data Source=dwh_dev.klm.infineon.com";
    
               try
               {
                   connection.Open();
                   LogFile(Server.MapPath("Log\\"), " Oracle connection started.");
                   return true;
               }
               catch (Exception ex)
               {
                   LogFile(Server.MapPath("Log\\"), ex.Message);          
                   return false;
               }      
            }
    
            public string SqlStatement_default()
            {
                         string sqlStatement = "select SQL_QUERY from INDICATOR_GADGET where visible = 'Y' and rownum < 10";
                         return sqlStatement;
            }
            public string SqlStatement(string indicator)
            {
                string sqlStatement = "select SQL_QUERY from INDICATOR_GADGET where visible = 'Y' and indicator = '"+ indicator +"'";
                return sqlStatement;
            }
            
            public void ExecuteSqlStatement ()
            {
               
            }
    
    
            private void MessageBoxShow(Page page, string message)
            {
                Literal ltr = new Literal();
                ltr.Text = @"<script type='text/javascript'> alert('" + message + "') </script>";
                page.Controls.Add(ltr);
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    BindIndicator_default();
                    // ExecuteSqlStatement();
                }
                else
                {
                   // DropDownList ddlIndicator = (DropDownList)dataGridView.HeaderRow.FindControl("ddlIndicator");
                   // ddlIndicator.SelectedIndex = ddlIndicator.Items.IndexOf(ddlIndicator.Items.FindByText(ddlIndicator.SelectedItem.ToString()));
                   // ViewState["test"] = ddlIndicator.SelectedItem;
                  //  ddlIndicator.Items.FindByText(ViewState["test"].ToString()).Selected = true;
                    //ViewState["test"] = ddlIndicator.SelectedItem;
                   // ddlIndicator.SelectedIndex = ddlIndicator.Items.IndexOf(ddlIndicator.Items.FindByValue(ddlIndicator.SelectedItem.Value));
                }
            }
    
            protected void BindIndicator_default()
            {
                try
                {
                    string sqlCommand = SqlStatement_default();
                    string IndicatorQuery = "";
    
                    if (GetOracleConnection())
                    {
                        OracleCommand cmd = new OracleCommand(sqlCommand, connection);
                        cmd.CommandType = CommandType.Text;
                        OracleDataAdapter da = new OracleDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        da.Fill(dataSet);
                        int RowCount = ((dataSet.Tables[0].Rows.Count) - 1);
                        DataSet dSet = new DataSet();
    
                        for (int i = 0; i <= RowCount; i++)
                        {
                            IndicatorQuery = dataSet.Tables[0].Rows[i][0].ToString();
                            OracleCommand command = new OracleCommand(IndicatorQuery, connection);
                            command.CommandType = CommandType.Text;
                            OracleDataAdapter dataAdapter = new OracleDataAdapter(command);
                            dataAdapter.Fill(dSet);
                            dataGridView.DataSource = dSet;
                            dataGridView.DataBind();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxShow(this, ex.Message.ToString());
                }
                   /* OracleCommand command = new OracleCommand(sqlStatement, connection);               
                    ddlIndicator.DataSource = command.ExecuteReader();
                    ddlIndicator.DataTextField = "Indicator";
                    ddlIndicator.DataValueField = "Indicator";
                    ddlIndicator.DataBind();
                    ddlIndicator.Items.FindByValue(ViewState["Filter"].ToString()).Selected = true;*/
            }
    
            protected void BindIndicator(string selectedValue)
            {
                
                string sqlCommand = SqlStatement(selectedValue);
                string IndicatorQuery = "";
    
                if (GetOracleConnection())
                {
                    try
                    {
                        OracleCommand cmd = new OracleCommand(sqlCommand, connection);
                        cmd.CommandType = CommandType.Text;
                        OracleDataAdapter da = new OracleDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        da.Fill(dataSet);
                        int RowCount = ((dataSet.Tables[0].Rows.Count) - 1);
                        DataSet dSet = new DataSet();
    
                        for (int i = 0; i <= RowCount; i++)
                        {
                            IndicatorQuery = dataSet.Tables[0].Rows[i][0].ToString();
                            OracleCommand command = new OracleCommand(IndicatorQuery, connection);
                            command.CommandType = CommandType.Text;
                            OracleDataAdapter dataAdapter = new OracleDataAdapter(command);
                            dataAdapter.Fill(dSet);
                            dataGridView.DataSource = dSet;
                            dataGridView.DataBind();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBoxShow(this, ex.Message.ToString());
                    }
                }
            }
            protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            {
              // Response.Write("ddd");
                try
                {
                    DropDownList ddlIndicator = (DropDownList)dataGridView.HeaderRow.FindControl("ddlIndicator");
                    string selectedValue = ddlIndicator.SelectedValue.ToString();
                    int selectedIndex = ddlIndicator.SelectedIndex;
                    
                    if (selectedValue != "" && selectedValue != "default")
                    {
                        BindIndicator(selectedValue);
                        //lIndicator.SelectedItem;
                       // ddlIndicator.SelectedIndex = ddlIndicator.Items.IndexOf(ddlIndicator.Items.FindByText(selectedValue));
                        //ddlIndicator.Items.FindByValue(selectedValue).Selected = true;
                        //ddlIndicator.SelectedIndex = 1;
                        ddlIndicator.SelectedIndex = ddlIndicator.Items.IndexOf(ddlIndicator.Items.FindByValue(ddlIndicator.SelectedItem.Value));
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxShow(this, ex.Message.ToString());
                }
            }
    
            protected void dataGridView_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if(e.Row.RowType == DataControlRowType.Header)
                {
                }
    
                if(e.Row.RowType == DataControlRowType.DataRow)
                {
                   
                }
            }
    
            protected void dataGridView_SelectedIndexChanged(object sender, EventArgs e)
            {
                
            }
        }
    }

  2. #2
    Non-Member
    Join Date
    Oct 2013
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all go to property list of Dropdownlist ( or press F4), select auto post back equal to true after that run your website.
    Auto Post Back is by default False.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •