Click here to Skip to main content
15,891,777 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionRe: displaying selected records Pin
Amit Patel19851-Sep-09 0:22
Amit Patel19851-Sep-09 0:22 
QuestionHow to store picture into database and retrieval Pin
abglorie31-Aug-09 18:37
abglorie31-Aug-09 18:37 
AnswerRe: How to store picture into database and retrieval Pin
swtlibra31-Aug-09 18:58
swtlibra31-Aug-09 18:58 
QuestionBest Method For AJAX Web Wizards Pin
Adam R Harris31-Aug-09 14:50
Adam R Harris31-Aug-09 14:50 
QuestionVirtual path in Web Application Model. Pin
Nadia Monalisa31-Aug-09 13:04
Nadia Monalisa31-Aug-09 13:04 
Questionhow to convert multiline textbox text to image Pin
Shuaib wasif khan31-Aug-09 13:01
Shuaib wasif khan31-Aug-09 13:01 
AnswerRe: how to convert multiline textbox text to image Pin
Christian Graus31-Aug-09 14:00
protectorChristian Graus31-Aug-09 14:00 
QuestionDropdown list value is not retaining on page post back [modified] Pin
skhan1731-Aug-09 7:10
skhan1731-Aug-09 7:10 
Dear all,
I am having problem with placing the proper condition inside the postback method. I am trying to do the following:
1. There are 2 dropdown lists in my program.
2. I have two DropDownLists databound on the webform. The autopostback of the first dropdown list control is set to true. The contents of the first dropdown list is hardcoded. The contents of the second depend on the selected item in the first. In other words: The selectedvalue of the first DropDownList is passed as a parameter for the query at the basis of the second DropDownList's datasource. And this works: Whenever I click on an item in the first DropDownList, the dependant items are shown in the second DropDownList.

3. If I click submit then the specific rows from the DB will be pulled based on the values selected from dropdown list 1 and dropdown list 2.

Problem: In the postback method I think all the times the "ANY" MLNO is selected instead of selecting a specific value from the dropdown list 2. And that's why always all the values are pulled from the DB.

The code is as follows:
Code:

using System.Data;
using System.Data.OleDb;
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 System.IO;
using System.Xml;
using System.Globalization;


namespace HIV
{
    /// <summary>
    /// Summary description for run_specific_query.
    /// </summary>
    public class run_specific_query : System.Web.UI.Page
    {
        protected HIV.Controls.NavMenu navMenu;
        protected HIV.Controls.NavSubMenu navSubMenu;
        protected System.Web.UI.HtmlControls.HtmlGenericControl message;
        protected System.Web.UI.WebControls.Label resultsLabel;
        protected System.Web.UI.WebControls.DropDownList Specific_Query_DDL;
        protected System.Web.UI.WebControls.DropDownList mlno_DDL;
        //protected System.Web.UI.WebControls.TextBox date_TB;
        protected System.Web.UI.WebControls.CompareValidator dateValidator;
        protected System.Web.UI.WebControls.DataGrid resultsDatagrid;
        protected System.Web.UI.WebControls.Button submitButton;
        protected System.Web.UI.WebControls.Label data_src;
        protected System.Web.UI.WebControls.LinkButton exportLinkbutton;

        private void Page_Load(object sender, System.EventArgs e)
        {
            navMenu.SelectedMainItem = HIV.Controls.NavMenu.MainItems.QUERY;
            navSubMenu.SelectedMainItem = HIV.Controls.NavMenu.MainItems.QUERY;
            navSubMenu.SelectedSubItem = HIV.Controls.NavSubMenu.SubItems.RUN_SPECIFIC_QUERY;
            
            if (this.IsPostBack)
            {
                if(Specific_Query_DDL.SelectedItem.Value=="ResistantL")
                {
                    getMLNO(Specific_Query_DDL.SelectedItem.Value);
                }
                if(Specific_Query_DDL.SelectedItem.Value=="NegativeL")
                {
                    getMLNO(Specific_Query_DDL.SelectedItem.Value);
                }
           }
           
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            BuildQueryForm();
            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.exportLinkbutton.Click += new System.EventHandler(this.exportLinkbutton_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        protected void BuildQueryForm()
        {
            try
            {
                this.submitButton.Click += new System.EventHandler(this.submitButton_Click);
                this.Load += new System.EventHandler(this.Page_Load);
            }
            catch(Exception e)
            {
                message.InnerHtml = "Exception: " + e.ToString();
            }
        }

        private void getMLNO(string selectedvalue)
        {
            if(selectedvalue=="ResistantL")
            {
                string sql= "SELECT re_MLNO, MAX(re_SpecimenDate)-MIN(re_SpecimenDate) AS DaysSeronegative FROM ml_hiv_status WHERE (re_HIV1_Status=0) GROUP BY re_MLNO";
            
                OleDbConnection connection = new OleDbConnection(HIV.Database.DataConstants.CONNECTION_STRING);
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                OleDbCommand command = new OleDbCommand(sql, connection);
            
                DataSet ds = new DataSet();
                adapter.SelectCommand = command;

                if (adapter.Fill(ds) > 0)
                {
                    foreach (DataRow r in ds.Tables[0].Rows)
                    {
                        if(Convert.ToInt32(r["DaysSeronegative"]) < 2555)  
                        {
                            r.Delete();
                        }
                    }
                    DataView view = ds.Tables[0].DefaultView;
                    mlno_DDL.DataSource = view;
                    mlno_DDL.DataValueField="re_MLNO";
                    mlno_DDL.DataTextField = "re_MLNO";
                    mlno_DDL.DataBind();
                    resultsLabel.Visible= true;
                    mlno_DDL.Items.Insert(0, "ANY");
                }
                connection.Close();
            }
            if(selectedvalue=="NegativeL")
            {
                string sql= "SELECT re_MLNO,sum(re_HIV1_Status) AS hivNeg, MAX(re_SpecimenDate)- MIN(re_SpecimenDate) AS DaysSeronegative  FROM ml_hiv_status  GROUP BY re_MLNO";

                OleDbConnection connection = new OleDbConnection(HIV.Database.DataConstants.CONNECTION_STRING);
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                OleDbCommand command = new OleDbCommand(sql, connection);
            
                DataSet ds = new DataSet();
                adapter.SelectCommand = command;

                if (adapter.Fill(ds) > 0)
                {
                    foreach (DataRow r in ds.Tables[0].Rows)
                    {
                        if(Convert.ToInt32(r["hivNeg"]) != 0)
                        {
                            r.Delete();
                        }
                    }
                    DataView view = ds.Tables[0].DefaultView;
                    mlno_DDL.DataSource = view;
                    mlno_DDL.DataValueField="re_MLNO";
                    mlno_DDL.DataTextField = "re_MLNO";
                    mlno_DDL.DataBind();
                    resultsLabel.Visible= true;
                    mlno_DDL.Items.Insert(0, "ANY");
                }
                connection.Close();
            }
            
        }
        private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
        }
        private void submitButton_Click(object sender, System.EventArgs e)
        {
            if(Specific_Query_DDL.SelectedItem.Value=="default")
            {
                resultsLabel.Visible= true;
                resultsLabel.Text ="Please select a specific query from the dropdown list";
                exportLinkbutton.Visible = false;
            }
            if(Specific_Query_DDL.SelectedItem.Value=="ResistantL")
            {
                if(mlno_DDL.SelectedItem.Value=="ANY")
                {
                    executeResistantListQuery_ANY();
                }    
                else if(mlno_DDL.SelectedItem.Value!="ANY") 
                {
                    executeResistantListQuery_MLNO(mlno_DDL.SelectedItem.Value);
                }
            }
            if(Specific_Query_DDL.SelectedItem.Value=="NegativeL")
            {
                if(mlno_DDL.SelectedItem.Value=="ANY")
                {
                    executeNegativeListQuery_ANY();
                }
                else if(mlno_DDL.SelectedItem.Value!="ANY")
                {
                      executeNegativeListQuery_MLNO(mlno_DDL.SelectedItem.Value);
                }
            }
            
        }

Thank you all who will try to solve the problem. To me it seems that the the second dropdown list is getting refreshed everytime I am posting the page back/submit and that's why "ANY" is getting selected and thus it's pulling all the data. This is not the whole code, this is only the part I thought might be useful to suggest any solution. Though other people might feel it's useless(!).
AnswerRe: Dropdown list value is not retaining on page post back Pin
Abhishek Sur31-Aug-09 10:36
professionalAbhishek Sur31-Aug-09 10:36 
GeneralRe: Dropdown list value is not retaining on page post back Pin
skhan1731-Aug-09 11:09
skhan1731-Aug-09 11:09 
GeneralRe: Dropdown list value is not retaining on page post back Pin
Abhishek Sur31-Aug-09 11:40
professionalAbhishek Sur31-Aug-09 11:40 
GeneralRe: Dropdown list value is not retaining on page post back Pin
Christian Graus31-Aug-09 14:02
protectorChristian Graus31-Aug-09 14:02 
GeneralRe: Dropdown list value is not retaining on page post back Pin
Abhishek Sur31-Aug-09 23:25
professionalAbhishek Sur31-Aug-09 23:25 
AnswerRe: Dropdown list value is not retaining on page post back Pin
Christian Graus31-Aug-09 14:07
protectorChristian Graus31-Aug-09 14:07 
QuestionReferencing HTML input boxes correctly Pin
dptalt31-Aug-09 5:10
dptalt31-Aug-09 5:10 
AnswerRe: Referencing HTML input boxes correctly Pin
Not Active31-Aug-09 6:44
mentorNot Active31-Aug-09 6:44 
GeneralRe: Referencing HTML input boxes correctly Pin
dptalt31-Aug-09 9:15
dptalt31-Aug-09 9:15 
GeneralRe: Referencing HTML input boxes correctly Pin
Not Active31-Aug-09 9:56
mentorNot Active31-Aug-09 9:56 
GeneralRe: Referencing HTML input boxes correctly Pin
Abhishek Sur31-Aug-09 10:44
professionalAbhishek Sur31-Aug-09 10:44 
GeneralRe: Referencing HTML input boxes correctly Pin
dptalt1-Sep-09 1:35
dptalt1-Sep-09 1:35 
QuestionTimeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Pin
ncsubbu31-Aug-09 2:47
professionalncsubbu31-Aug-09 2:47 
AnswerRe: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Pin
Tamer Oz31-Aug-09 2:55
Tamer Oz31-Aug-09 2:55 
AnswerRe: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Pin
Abhijit Jana31-Aug-09 3:06
professionalAbhijit Jana31-Aug-09 3:06 
AnswerRe: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Pin
Fayu31-Aug-09 6:50
Fayu31-Aug-09 6:50 
GeneralRe: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Pin
Christian Graus31-Aug-09 14:19
protectorChristian Graus31-Aug-09 14:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.