...

View Full Version : Query On ASP Using Radio Buttons



Zoneblaster
03-03-2007, 03:52 PM
Hi i am using Dreamweaver to do my ASP i need to put some queries i made in access using radio buttons so e.g if a user clicks on a Query1 Radio button for example should see the query 1 i made in access db and if he clicks on Query2 Radio Button he should see query 2

Thank you very much for your help

BarrMan
03-03-2007, 08:02 PM
Your explanation had no code in it and was very rough so this is what I could understand from it.

If Request.Form("QueryRadio") = "Query1" Then
SQL = 'Query1 SQL
ElseIf Request.Form("QueryRadio") = "Query2" Then
SQL = 'Query2 SQL
End If

Zoneblaster
03-03-2007, 10:44 PM
Your explanation had no code in it and was very rough so this is what I could understand from it.

If Request.Form("QueryRadio") = "Query1" Then
SQL = 'Query1 SQL
ElseIf Request.Form("QueryRadio") = "Query2" Then
SQL = 'Query2 SQL
End If

yes yes like that but how do i make it show up? on the same page in tables?

example says name and surname
If Request.Form("QueryRadio") = "Query1" Then
SQL = "SELECT name, surname from subs"
ElseIf Request.Form("QueryRadio) = "Query2" Then
SQL = 'Query2 SQL
End If

so now when i click on radio button Query1 and press the button it show show me those names and surname from table subs

i hope you understand what i mean thank you very much


I have done this on C# i need to do it on asp here is the C# code maybe it will help you understand what i mean.

private void getQueryBtn_Click(object sender, EventArgs e)
{
if (queryButton1.Checked == true)
{
try
{
DataTable table = new DataTable();
string command, ARTICLEID, ArticleType, ArticleTitle, DateSubmitted, ArticleDifficulty; ;
int recordCount;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Gardening.mdb";

OleDbConnection myCon = new OleDbConnection(strCon);
command = "SELECT ArticleDetails.ARTICLEID, ArticleDetails.ArticleType, ArticleDetails.ArticleTitle, ArticleDetails.DateSubmitted, ArticleDetails.ArticleDifficulty FROM ArticleDetails ORDER BY ArticleDetails.ArticleTitle";
OleDbDataAdapter myAdapter = new OleDbDataAdapter(command, myCon);

table.Clear();
recordCount = myAdapter.Fill(table);

if (recordCount != 0)
{
for (int i = 0; i < recordCount; i++)
{
ARTICLEID = Convert.ToString(table.Rows[i][0]);
queryResultshow.AppendText(ARTICLEID + " ");

ArticleType = Convert.ToString(table.Rows[i][1]);
queryResultshow.AppendText(ArticleType + " ");

ArticleTitle = Convert.ToString(table.Rows[i][2]);
queryResultshow.AppendText(ArticleTitle + " ");

DateSubmitted = Convert.ToString(table.Rows[i][3]);
queryResultshow.AppendText(DateSubmitted + " ");

ArticleDifficulty = Convert.ToString(table.Rows[i][4]);
queryResultshow.AppendText(ArticleDifficulty + "\n");
}

}
}
catch (Exception exceptionObject)
{
MessageBox.Show(exceptionObject.Message);
}
}
if (queryButton2.Checked == true)
{
try
{
string resulttextbox = nameSpecified.Text;
DataTable table = new DataTable();
string command, AuthurForeName, AuthurSurName, AuthurTown, SubscriberForeName, SubscriberSurName, SubscriberTown; ;
int recordCount;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Gardening.mdb";

OleDbConnection myCon = new OleDbConnection(strCon);
command = "SELECT AuthurDetails.ForeName, AuthurDetails.SurName, AuthurDetails.AuthurTown, LoginDetails.ForeName, LoginDetails.SurName, LoginDetails.UserTown FROM AuthurDetails, LoginDetails WHERE (((AuthurDetails.AuthurTown)=" + "'" + nameSpecified.Text + "'" + ") AND ((LoginDetails.UserTown)=" + "'" + nameSpecified.Text + "'" + ")) ORDER BY AuthurDetails.ForeName";
OleDbDataAdapter myAdapter = new OleDbDataAdapter(command, myCon);

table.Clear();
recordCount = myAdapter.Fill(table);

if (recordCount != 0)
{
for (int i = 0; i < recordCount; i++)
{
AuthurForeName = Convert.ToString(table.Rows[i][0]);
queryResultshow.AppendText(AuthurForeName + " ");

AuthurSurName = Convert.ToString(table.Rows[i][0]);
queryResultshow.AppendText(AuthurSurName + " ");

AuthurTown = Convert.ToString(table.Rows[i][0]);
queryResultshow.AppendText(AuthurTown + " ");

SubscriberForeName = Convert.ToString(table.Rows[i][3]);
queryResultshow.AppendText(SubscriberForeName + " ");

SubscriberSurName = Convert.ToString(table.Rows[i][4]);
queryResultshow.AppendText(SubscriberSurName + " ");

SubscriberTown = Convert.ToString(table.Rows[i][5]);
queryResultshow.AppendText(SubscriberTown + "\n");

}

}
}
catch (Exception exceptionObject)
{
MessageBox.Show(exceptionObject.Message);
}
}
if (queryButton3.Checked == true)
{
try
{
string datefrom = dateFromtxt.Text;
string dateto = dateTotxt.Text;
DataTable table = new DataTable();
string command, ArticleTitle, DateSubmitted, ArticleType; ;
int recordCount;
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Gardening.mdb";

OleDbConnection myCon = new OleDbConnection(strCon);
command = "SELECT ArticleDetails.ArticleTitle, ArticleDetails.DateSubmitted, ArticleDetails.ArticleType FROM ArticleDetails WHERE (((ArticleDetails.DateSubmitted) Between" + "#" + dateFromtxt.Text + "#" + "And" + "#" + dateTotxt.Text + "#" + ") AND ((ArticleDetails.ArticleType)='Plants'))";
OleDbDataAdapter myAdapter = new OleDbDataAdapter(command, myCon);

table.Clear();
recordCount = myAdapter.Fill(table);

if (recordCount != 0)
{
for (int i = 0; i < recordCount; i++)
{
ArticleTitle = Convert.ToString(table.Rows[i][0]);
queryResultshow.AppendText(ArticleTitle + " ");

DateSubmitted = Convert.ToString(table.Rows[i][1]);
queryResultshow.AppendText(DateSubmitted + " ");

ArticleType = Convert.ToString(table.Rows[i][2]);
queryResultshow.AppendText(ArticleType + "\n");
}

}
}
catch (Exception exceptionObject)
{
MessageBox.Show(exceptionObject.Message);
}
}
}

private void queryButton2_CheckedChanged(object sender, EventArgs e)
{
nameSpecified.Enabled = true;
queryResultshow.Text = "";
}

private void queryButton3_CheckedChanged(object sender, EventArgs e)
{
dateFromtxt.Enabled = true;
dateTotxt.Enabled = true;
queryResultshow.Text = "";
}

private void queryButton1_CheckedChanged(object sender, EventArgs e)
{
queryResultshow.Text = "";
}
}
}

BarrMan
03-04-2007, 04:57 PM
I have a hard time understanding what you want.
As I can see, you're new to asp so I'd suggest you to visit www.w3schools.com to learn asp and html.

miranda
03-06-2007, 06:41 PM
If you can do this in .Net why bother using outdated classic asp? Stick with .Net and do it there.

But to do this in classic you will need to
A) create a client side javascript to handle the onClick event of the radio button to submit the form.
B)For your server side asp code you will need to look to see which of the radio buttons was clicked and determine which sql statement to run. also you will need to write some code to display the data as classic asp does not have the datagrid control ASP.Net 1.1 has or the GridView control that ASP.Net 2.0 has. (That is one reason to stick to Asp.Net)
C) because the server side code will try to run on page load you will need to make this run at postback only.
This can be accomplished by using some type of control structure to determine the value of your radio button that was selected. an if statement or a select case statement. and then running the associated sql code and displaying the results

example

If Request.Form("QueryRadio") = "Query1" Then
Call DisplayTable("Query1")
ElseIf Request.Form("QueryRadio") = "Query2" Then
Call DisplayTable("Query2")
End If

Sub DisplayTable(ByVal Query)
'Run your query and display the data in the table

End Sub



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum