Click here to Skip to main content
15,896,207 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: simple application Pin
Gaurav Dudeja India26-Aug-09 21:17
Gaurav Dudeja India26-Aug-09 21:17 
Questionhow to locate one button near right position of the screen? Pin
Seraph_summer26-Aug-09 10:20
Seraph_summer26-Aug-09 10:20 
AnswerRe: how to locate one button near right position of the screen? Pin
Not Active26-Aug-09 10:53
mentorNot Active26-Aug-09 10:53 
AnswerRe: how to locate one button near right position of the screen? Pin
Gaurav Dudeja India26-Aug-09 21:22
Gaurav Dudeja India26-Aug-09 21:22 
QuestionCustom Validator Pin
shaik_mr26-Aug-09 7:48
shaik_mr26-Aug-09 7:48 
AnswerRe: Custom Validator Pin
Not Active26-Aug-09 10:56
mentorNot Active26-Aug-09 10:56 
AnswerRe: Custom Validator Pin
Christian Graus26-Aug-09 15:04
protectorChristian Graus26-Aug-09 15:04 
Questionproblem is dynamic dropdown list control ...Please help!!! Pin
skhan1726-Aug-09 7:37
skhan1726-Aug-09 7:37 
Hello,
I want submit button to fetch different query results from the database. So I have implemented which query to execute inside the SubmitButton_Click function/method. But it's not working as I have desired....it's fetching one query every time.

To give you a brief idea, in my .aspx I have 2 dropdown lists (1 to select which query to run and another one to select which patient number should I pull from the DB), 1 text box which contains date field. I have kinda found what's causing the problem....but don't know how to solve it. Somehow from the drop down list "ANY" is selected all the times.....no matter what I select from the second dropdown list. Any suggestion would be really helpful.

The code is as follows:



using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
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;

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_QUER Y;

getMLNO();

//if (!this.IsPostBack)
//LoadQueryLinks();
}

#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(); [This function/method is calling the submit button function]
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.submitButton.Click += new System.EventHandler(this.submitButton_Click);
//this.Load += new System.EventHandler(this.Page_Load);
this.exportLinkbutton.Click += new System.EventHandler(this.exportLinkbutton_Click);
this.Load += new System.EventHandler(this.Page_Load); [after the data is pulled from the DB the export to excel button should show up, so I have implemented this here]

}
#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()
{
OleDbConnection connection = new OleDbConnection(HIV.Database.DataConstants.CONNECT ION_STRING);
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand("SELECT DISTINCT re_MLNO FROM ml_hiv_status", connection);

DataSet ds = new DataSet();
adapter.SelectCommand = command;

if (adapter.Fill(ds) > 0)
{
int adp= adapter.Fill(ds);
DataView view = ds.Tables[0].DefaultView;
mlno_DDL.DataSource = view;
mlno_DDL.DataValueField="re_MLNO";
mlno_DDL.DataBind();
resultsLabel.Visible= true;
//resultsLabel.Text ="TEST MESSAGE: You Have selected the DB "+ adp + Specific_Query_DDL.SelectedItem.Value;
mlno_DDL.Items.Insert(0, "ANY");
}
connection.Close();
}

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=="Resista ntL")
{
resultsLabel.Visible= true;
resultsLabel.Text ="You Have selected"+ Specific_Query_DDL.SelectedItem.Value;
}
if(Specific_Query_DDL.SelectedItem.Value=="Negativ eL")
{
resultsLabel.Visible= true;
resultsLabel.Text ="You Have selected"+ Specific_Query_DDL.SelectedItem.Value;
}
if(Specific_Query_DDL.SelectedItem.Value=="Positiv eL") [The problem is here in this if else block]
{
if(mlno_DDL.SelectedItem.Value=="ANY")
{
executePositiveListQuery_ANY(); [All the time this one is called but...]
}
else //if(mlno_DDL.SelectedItem.Value!="ANY")
{
executePositiveListQuery_MLNO(mlno_DDL.SelectedIte m.Value); [...I want this method to be called as well when I am selecting a specific patient number]
}
}
if(Specific_Query_DDL.SelectedItem.Value=="DeadL")
{
resultsLabel.Visible= true;
resultsLabel.Text ="You Have selected"+ Specific_Query_DDL.SelectedItem.Value;
}

}

public void executePositiveListQuery_ANY()
{
string sql= "SELECT DISTINCT re_MLNO FROM ml_hiv_status WHERE (re_HIV1_Status=1 AND re_HIV2_Status=1)";
try
{
OleDbConnection connection = new OleDbConnection(HIV.Database.DataConstants.CONNECT ION_STRING);
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(sql, connection);

DataSet ds = new DataSet();
adapter.SelectCommand = command;

int count = adapter.Fill(ds);

if (count > 0 && count <= 200)
{
DataView view = ds.Tables[0].DefaultView;
//view.Sort=e.SortExpression;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = true;
resultsLabel.Text = count.ToString() + " results found.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
}
else if (count> 200)
{
DataView view = ds.Tables[0].DefaultView;
//view.Sort=e.SortExpression;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = false;
resultsLabel.Text = "More than 200 results found. Please Click the Export to Excel Link to Download the Results.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
}
else
{
resultsLabel.Text = "No results found.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = false;
resultsDatagrid.Visible = false;
}
connection.Close();
}
catch(Exception ex)
{
message.InnerHtml = "SQL: " + sql + "<p></p>" + ex.ToString();
}

//resultsLabel.Text ="You Have selected"+ Specific_Query_DDL.SelectedItem.Value;
}

public void executePositiveListQuery_MLNO(string selected_MLNO)
{
/*string sql= "SELECT * FROM ml_hiv_status WHERE (re_HIV1_Status=1 AND re_HIV2_Status=1)";
try
{
OleDbConnection connection = new OleDbConnection(HIV.Database.DataConstants.CONNECT ION_STRING);
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(sql, connection);

DataSet ds = new DataSet();
adapter.SelectCommand = command;

int count = adapter.Fill(ds);

if (count > 0 && count <= 200)
{
DataView view = ds.Tables[0].DefaultView;
//view.Sort=e.SortExpression;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = true;
resultsLabel.Text = count.ToString() + " results found.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
}
else if (count> 200)
{
DataView view = ds.Tables[0].DefaultView;
//view.Sort=e.SortExpression;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = false;
resultsLabel.Text = "More than 200 results found. Please Click the Export to Excel Link to Download the Results.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
}
else
{
resultsLabel.Text = "No results found.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = false;
resultsDatagrid.Visible = false;
}
connection.Close();
}
catch(Exception ex)
{
message.InnerHtml = "SQL: " + sql + "<p></p>" + ex.ToString();
}*/

resultsLabel.Text ="You Have selected"+ selected_MLNO;
}

private void exportLinkbutton_Click(object sender, System.EventArgs e)
{
resultsDatagrid.Visible = true;
DataGridItem tblGrid=resultsDatagrid.Items[0];
ArrayList alLinks= new ArrayList();
TableCell TC;
LinkButton LB;

for(int i=0; i<tblGrid.Cells.Count - 1; i++)
{
TC=tblGrid.Cells[i];
if(TC.Controls.Count> 0)
{
LB=(LinkButton)TC.Controls[0];
resultsDatagrid.Items[0].Cells[i].Controls.Clear();
resultsDatagrid.Items[0].Cells[i].Text=LB.Text;
}
else
LB=new LinkButton();

alLinks.Add(LB);
}

Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
resultsDatagrid.EnableViewState = false;

System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
resultsDatagrid.RenderControl(hw);
//TextWriter TW= File.CreateText(Server.MapPath("ExportToExcel.xls" ));

Response.Write(tw.ToString());
Response.End();

for(int i=0; i<tblGrid.Cells.Count - 1; i++)
{
LB = (LinkButton)alLinks[i];
//TC=tblGrid.Rows[0].Cells[i];
resultsDatagrid.Items[0].Cells[i].Controls.Add(LB);
}
}
}
}



Please help! Thanks to everyone who give their time and energy to solve this.
AnswerRe: problem is dynamic dropdown list control ...Please help!!! Pin
droth1726-Aug-09 8:52
droth1726-Aug-09 8:52 
GeneralRe: problem is dynamic dropdown list control ...Please help!!! Pin
skhan1726-Aug-09 9:08
skhan1726-Aug-09 9:08 
QuestionMoving page from root to folder causing 404 error Pin
Linda Sacca26-Aug-09 5:03
Linda Sacca26-Aug-09 5:03 
AnswerRe: Moving page from root to folder causing 404 error Pin
droth1726-Aug-09 10:15
droth1726-Aug-09 10:15 
Questionabout to generate url for every node Pin
babji rao26-Aug-09 4:53
babji rao26-Aug-09 4:53 
AnswerRe: about to generate url for every node Pin
N a v a n e e t h26-Aug-09 4:58
N a v a n e e t h26-Aug-09 4:58 
QuestionASP.Net page and Strongly Named Assembly Pin
Daemoncat26-Aug-09 3:43
Daemoncat26-Aug-09 3:43 
Questionscript files in adrotator control? Pin
Member 387988126-Aug-09 3:33
Member 387988126-Aug-09 3:33 
Questiontreeview binding Pin
Rajeshwar Code- Developer26-Aug-09 2:48
Rajeshwar Code- Developer26-Aug-09 2:48 
AnswerRe: treeview binding Pin
Coding C#26-Aug-09 2:52
Coding C#26-Aug-09 2:52 
GeneralRe: treeview binding Pin
Rajeshwar Code- Developer26-Aug-09 3:20
Rajeshwar Code- Developer26-Aug-09 3:20 
QuestionAccess a perticular gridview cell via javascript Pin
benams26-Aug-09 2:23
benams26-Aug-09 2:23 
AnswerRe: Access a perticular gridview cell via javascript Pin
keyur satyadev26-Aug-09 2:30
keyur satyadev26-Aug-09 2:30 
AnswerRe: Access a perticular gridview cell via javascript Pin
Coding C#26-Aug-09 2:36
Coding C#26-Aug-09 2:36 
GeneralRe: Access a perticular gridview cell via javascript Pin
benams26-Aug-09 21:04
benams26-Aug-09 21:04 
GeneralRe: Access a perticular gridview cell via javascript Pin
Coding C#26-Aug-09 22:04
Coding C#26-Aug-09 22:04 
GeneralRe: Access a perticular gridview cell via javascript Pin
benams26-Aug-09 23:09
benams26-Aug-09 23:09 

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.