Server simple search functionality - c#

and thank you for taking the time to read my post! It is very much appreciated. I am pretty new to ASP.Net and I am trying to create a simple page where I can search a table on my SQL Server database.
Here is the asp.net code:
<%# Page Language="C#" MasterPageFile="~/PantryAdmin.Master" AutoEventWireup="true" CodeFile="ProductSearch.aspx.cs" Inherits="RampantryF.ProductSearch" %>
<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<div>
<asp:TextBox ID="SearchBox" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:fall16_g8ConnectionString %>" SelectCommand="SELECT * FROM [PRODUCT]"></asp:SqlDataSource>
</div>
</asp:Content>
My code behind:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace RampantryF
{
public partial class ProductSearch : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["fall16_g8ConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string find = "select * from PRODUCT where(PRODUCT_NAME like '%' + #PRODUCT_NAME + '%')";
SqlCommand comm = new SqlCommand(find, con);
comm.Parameters.Add("#PRODUCT_NAME", SqlDbType.NVarChar).Value = SearchBox.Text;
con.Open();
comm.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
da.Fill(ds, "PRODUCT_NAME");
GridView2.DataSource = ds;
GridView2.DataBind();
con.Close();
}
}
}
The page loads fine but when you press the 'search' button it just refreshes the page instead of loading the data into the gridview. I am wondering what is going on and how I can fix it.
Let me know if any other information is needed. I am happy to provide it.
Thank you!

few changes done to your code, check how the like parameter assigned
protected void Button1_Click(object sender, EventArgs e)
{
string find = "select * from PRODUCT where PRODUCT_NAME like #PRODUCT_NAME";
SqlCommand comm = new SqlCommand(find, con);
comm.Parameters.Add("#PRODUCT_NAME", SqlDbType.NVarChar).Value = "%"+ SearchBox.Text + "%";
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds, "PRODUCT_NAME");
GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
}
Also change the AutoGenerateColumns as true in the aspx page.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="true">
</asp:GridView>

Related

Is it possible to use CASE statement on dynamically populated DropdownList?

I have a DropDownList that is dynamically populated from SQL Server database.
Currently, the DropDownList has 2 values, 0.20 and 0.30. However, users have informed us that they have several more values to add to the DropDownList.
If one of the users' clients presents water level of 0.20, they receive a discount of $100 or less.
The rest of the DropDownList values must receive $50 or less discount.
I am trying to use a CASE statement that ensures clients with 0.20 receive $100 or less discount and the rest $50 or less discount but I am stuck on how to handle the rest of the DropDownList values.
This is what I have been trying so far and I would like to know if it is possible to use CASE statement to handle this.
protected bool CheckWaterLevel(string wsize, decimal amt)
{
bool valueOK = false;
switch (wsize)
{
case "0.20":
if (amt <= 100)
valueOK = true;
break;
case "0.30":
if (amt <= 50)
valueOK = true;
break;
}
return valueOK;
}
In a nutshell, is it possible to replace case "0.30" with the values of DropDownList with the exception of 0.20?
The DropDownList control ID is ddlWaterLevels
HTML:
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<br /><br /><br />
<div>
<asp:Label ID="lblWater" runat="server" Text="Water Size" Width="100px"></asp:Label><br />
<asp:TextBox ID="txt_watersizes" placeholder="Enter new Water Size" Width="150px" runat="server"></asp:TextBox>
<asp:TextBox ID="txt_amount" placeholder="Enter amount" Width="100px" runat="server"></asp:TextBox>
<asp:Button ID="btn_add" runat="server" Text="Add It" onclick="btn_add_Click"
Width="100px" /><br /><br />
<asp:DropDownList ID="ddlWater" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlWater_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="TextBox1" placeholder="Enter new water size" Width="100px" runat="server"></asp:TextBox>
</div>
</asp:Content>
C#:
`using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : Page
{
string conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dropbind();
}
}
protected void btn_add_Click(object sender, EventArgs e)
{
ddlWater.Items.Clear();
SqlConnection con = new SqlConnection(conString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into WaterVolume(WaterSizes,Amount)values(#tsizes,#amount)";
com.Parameters.Clear();
com.Parameters.AddWithValue("#tsizes", txt_watersizes.Text);
com.Parameters.AddWithValue("#amount", txt_amount.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
Response.Write("Records successfully inserted");
clear();
dropbind();
}
private void clear()
{
txt_watersizes.Text = "";
txt_amount.Text = "";
}
private void dropbind()
{
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT WaterSizes FROM WaterVolume", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ddlWater.DataSource = dt;
ddlWater.DataTextField = "WaterSizes";
ddlWater.DataValueField = "WaterSizes";
ddlWater.DataBind();
ddlWater.Items.Insert(0, new ListItem { Text = "Select", Value = "" });
}
}
}
}
}
private void FetchData()
{
using (SqlConnection con = new SqlConnection(conString))
{
DataTable dt = new DataTable();
con.Open();
String sql = "SELECT Amount FROM WaterVolume WHERE WaterSizes = '" + ddlWater.SelectedItem.Text + "'";
SqlCommand cmd = new SqlCommand(sql, con);
// cmd.Connection.Open();
// cmd.ExecuteNonQuery();
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
//If you want to get mutiple data from the database then you need to write a simple looping
TextBox1.Text = dt.Rows[0]["Amount"].ToString();
}
// cmd.Connection.Close();
}
}
protected void ddlWater_SelectedIndexChanged(object sender, EventArgs e)
{
FetchData();
}
}
This is a better solution.
Obviously, I was overthinking it.
As you can see, a user selects water size, a textbox is automatically populated with the corresponding amount.
Since this is an internal app managed by only two people, and per their instruction, if there is a new water size, they don't have to contact us, they just enter the new water size and amount and voila, they are ready to go.
I just need to add some validations to ensure user cannot submit without entering data into the two boxes.

Show results of different queries in a single gridview on button click

I got a 'grid view' and three buttons in my web form. Now when I click 'button1' I want to show the respective result for query1 in 'grid view' and for 'button2' it should show the result of query2. Same for button3.
HTML of my web form :
<%# Page Title="" Language="C#" MasterPageFile="~/Master Page/Site1.Master" AutoEventWireup="true" CodeBehind="Dashboard.aspx.cs" Inherits="onlineshopping.Master_Page.WebForm1" %>
<asp:Content ID="Content1" runat="server" contentplaceholderid="BillingContent">
<div>
<table>
<tr>
<td>
<asp:Button ID="btn_dsbrdItems" runat="server" Text="Show Items" />
</td>
<td style="width:20px"></td>
<td>
<asp:Button ID="btn_dsbrdShowInvoices" runat="server" Text="Show Invoices" />
</td>
<td style="width:20px"></td>
<td>
<asp:Button ID="btn_dsbrShowUsers" runat="server" Text="Show Users" />
</td>
<td style="width:20px"></td>
</tr>
</table>
<table>
<tr>
<td>
<asp:GridView ID="gv_dashboard" runat="server" AutoGenerateColumns="false">
</asp:GridView>
</td>
</tr>
</table>
I know that I can bind a query result to 'grid view' and I have done that before. But I don't know what to do to achieve this. And I tried something. I knew its stupid & not gonna work. Still I just tried and didn't work as I expected. This is what I tried.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace onlineshopping.Master_Page
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings.Get("connectionstring").ToString());
string sql = "";
DataSet ds = new DataSet();
SqlDataAdapter da;
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void btn_dsbrdItems_Click(object sender, EventArgs e)
{
if(con.State==ConnectionState.Closed)
{ con.Open(); }
sql = "select * from item";
da = new SqlDataAdapter(sql, con);
da.Fill(ds);
gv_dashboard.DataSource = ds;
gv_dashboard.DataBind();
con.Close();
}
protected void btn_dsbrdShowInvoices_Click(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{ con.Open(); }
sql = "select * from invoice";
da = new SqlDataAdapter(sql, con);
da.Fill(ds);
gv_dashboard.DataSource = ds;
gv_dashboard.DataBind();
con.Close();
}
protected void btn_dsbrShowUsers_Click(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{ con.Open(); }
sql = "select * from tbl_users";
da = new SqlDataAdapter(sql, con);
da.Fill(ds);
gv_dashboard.DataSource = ds;
gv_dashboard.DataBind();
con.Close();
}
}
}
This is my web form
I am using 'master page' for side 'menu'. If this question is asked before please help me to find that link. I couldn't find.

Foreach loop on images in asp.net

I am new to Asp.Net & C#. I am developing a blog. I am able to save images in a folder and the image path in SQL Server. Now I want to retrieve the image from folder whose path is stored in SQL Server table.
I try this:
ASPX markup:
<body>
<form id="form1" runat="server">
<div class="row">
<div class="page-header"></div>
<div class="col-lg-3">
<asp:Image ID="Image1" CssClass="img-thumbnail" runat="server" />
</div>
</div>
</form>
</body>
Code-behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;
namespace Admin_Panel
{
public partial class Admin : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["stuconnection"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
string qry = "SELECT * FROM upload";
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
var filep = dr.GetString(1);
Image1.ImageUrl ="~/Images/" + filep;
}
con.Close();
}
}
}
But the above code will only show one image.
What I want: I want to show all images using a foreach loop or something like a loop, but I don't know how to do that.
Any help will be appreciated.
First of all, you should use asp.repeater:
<asp:Repeater ID="RptImages" runat="server">
<ItemTemplate>
<asp:Image ID="Img" runat="server" ImageUrl='<%# Container.DataItem %>'/>
</ItemTemplate>
</asp:Repeater>
Else:
public partial class Admin : System.Web.UI.Page
{
List<String> images = new List();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["stuconnection"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
string qry = "SELECT * FROM upload";
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
var filep = dr.GetString(1);
images.add(String.Concat("~/Images/", filep);
}
con.Close();
RptImages.DataSource = images;
RptImages.DataBind();
}
}

How to find a control in ASP.NET LoginView?

I can't find my label ID in LoginView Control, Just to explain what i'm trying to build. If you are NOT logged in you can only see the content from the database, but if your ARE logged in you can edit it. But right now i just need help to make it read the data from the database
Here is the ASP.NET Code-Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
{
using (SqlConnection connection = new SqlConnection("Data Source=10.138.22.47;Initial Catalog=Student10157;User ID=Studentxxxxx;Password=xxxxxxxxxxxxxxxxx"))
{
connection.Open();
SqlCommand cm = new SqlCommand("Select * from Content_Text", connection);
SqlDataReader dr;
dr = cm.ExecuteReader();
if (dr.Read())
{
lblLeft.text = dr["Text"].ToString();
}
}
}
}
}
Here is my ASP.NET code:
<asp:FormView runat="server" ID="viewdata">
<ItemTemplate>
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:Label ID="lblLeft" runat="server"></asp:Label>
</AnonymousTemplate>
<LoggedInTemplate>
<asp:TextBox ID="TxBLeft" runat="server" />
</LoggedInTemplate>
</asp:LoginView>
</ItemTemplate>
</asp:FormView>
I have tried as you can see to use a formview with the following C# code but that dont work either var lblLeft = (Label)viewData.FindControl("lblLeft");
Try This.
if (dr.Read())
{
Label lblLeft = (Label)viewData.FindControl("lblLeft")
lblLeft.text = dr["Text"].ToString();
}
FormView need in datasource, so i think you need somethink like this in your code
protected void Page_Load(object sender, EventArgs e)
{
{
using (SqlConnection connection = new SqlConnection("Data Source=10.138.22.47;Initial Catalog=Student10157;User ID=Studentxxxxx;Password=xxxxxxxxxxxxxxxxx"))
{
connection.Open();
SqlCommand cm = new SqlCommand("Select * from Content_Text", connection);
SqlDataReader dr;
dr = cm.ExecuteReader();
if (dr.Read())
{
viewdata.DataSource = new []{new { N = dr["Text"] }};
viewdata.DataBind();
}
}
}
}
and markup
<asp:FormView runat="server" ID="viewdata">
<ItemTemplate>
<asp:LoginView runat="server">
<AnonymousTemplate>
<asp:Label ID="lblLeft" runat="server" Text='<%# Eval("N") %>'></asp:Label>
</AnonymousTemplate>
<LoggedInTemplate>
<asp:TextBox ID="TxBLeft" runat="server" />
</LoggedInTemplate>
</asp:LoginView>
</ItemTemplate>
</asp:FormView>
UPDATE
if you have a few content_text you can try something like this
protected void Page_Load(object sender, EventArgs e)
{
{
using (SqlConnection connection = new SqlConnection("Data Source=10.138.22.47;Initial Catalog=Student10157;User ID=Studentxxxxx;Password=xxxxxxxxxxxxxxxxx"))
{
connection.Open();
SqlCommand cm = new SqlCommand("Select * from Content_Text", connection);
SqlDataReader dr;
dr = cm.ExecuteReader();
List<object> ds = new List<object>();
while (dr.Read())
{
ds.Add(new { N = dr["Text"] });
}
viewdata.DataSource = ds;
viewdata.DataBind();
}
}
}
You need to find the label in it's NamingContainer which is the ItemTemplate of the FormView:
protected void Page_Load(object sender, EventArgs e)
{
if (viewdata.CurrentMode == FormViewMode.ReadOnly)
{
LoginView lv = (LoginView)viewdata.FindControl("LoginView1");
Label lblLeft = (Label)lv.FindControl("lblLeft");
}
}
By the way, you should databind the label only if its not a postback:
if(!IsPostBack && viewdata.CurrentMode == FormViewMode.ReadOnly)
{
LoginView lv = (LoginView)viewdata.FindControl("LoginView1");
Label lblLeft = (Label)lv.FindControl("lblLeft");
using (SqlConnection connection = new SqlConnection("Data Source=10.138.22.47;Initial Catalog=Student10157;User ID=Studentxxxxx;Password=xxxxxxxxxxxxxxxxx"))
{
connection.Open();
using(var cm = new SqlCommand("Select TOP 1 Text from Content_Text", connection))
using(SqlDataReader dr = cm.ExecuteReader())
{
if(dr.Read())
{
lblLeft.Text = dr.GetString(dr.GetOrdinal("Text"));
}
}
}
}
You can find label in LoginView control as following:
LoginView logView = (LoginView)viewdata.FindControl("LoginView1");
Label lblLeft = (Label)logView.FindControl("lblLeft");
lblLeft.Text = "Your text goes here";

Search and display three dropdownlists with search button

I've created a search function with 3 DropDownLists and a search button. How will I display it on the same page?
Here's my code:
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//read sql server connection string from web.config file
string constring = ConfigurationManager.ConnectionStrings["AccreString"].ConnectionString;
SqlConnection conn = new SqlConnection(constring);
DataTable dt = new DataTable("emed_province");
using (conn)
{
conn.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM emed_province ORDER BY PROVINCE_NAME ASC", conn);
SqlDataAdapter adptr = new SqlDataAdapter(comm);
adptr.Fill(dt);
}
ddlProvince.DataSource = dt;
ddlProvince.DataTextField = "PROVINCE_NAME";
ddlProvince.DataValueField = "PROVINCE_CODE";
ddlProvince.DataBind();
}
}
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
string constring = ConfigurationManager.ConnectionStrings["AccreString"].ConnectionString;
SqlConnection conn = new SqlConnection(constring);
DataTable dt = new DataTable("emed_province");
using (conn)
{
conn.Open();
PROVINCE_CODE = '" + ddlProvince.SelectedValue + "'", conn);
SqlCommand comm = new SqlCommand("SELECT * FROM emed_city WHERE PROVINCE_CODE =#pcode", conn);
comm.Parameters.AddWithValue("#pcode", ddlProvince.SelectedValue);
SqlDataAdapter adptr = new SqlDataAdapter(comm);
adptr.Fill(dt);
SqlParameter param = new SqlParameter();
param.ParameterName = "#pcode";
param.Value = ddlProvince;
comm.Parameters.Add(param);
}
ddlCity.DataSource = dt;
ddlCity.DataTextField = "CITY_NAME";
ddlCity.DataValueField = "CITY_CODE";
ddlCity.DataBind();
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
string constring = ConfigurationManager.ConnectionStrings["AccreString"].ConnectionString;
SqlConnection conn = new SqlConnection(constring);
DataTable dt = new DataTable("emed_city");
using (conn)
{
conn.Open();
PROVINCE_CODE = '" + ddlProvince.SelectedValue + "'", conn);
SqlCommand comm = new SqlCommand("SELECT * FROM emed_doctors_hospitals WHERE CITY_CODE =#ccode", conn);
comm.Parameters.AddWithValue("#ccode", ddlCity.SelectedValue);
SqlDataAdapter adptr = new SqlDataAdapter(comm);
adptr.Fill(dt);
SqlParameter param = new SqlParameter();
param.ParameterName = "#ccode";
param.Value = ddlCity;
comm.Parameters.Add(param);
}
ddlSched.DataSource = dt;
ddlSched.DataTextField = "SCHEDULE";
ddlSched.DataValueField = "HOSPITAL_CODE";
ddlSched.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
When someone selects a value in the DropDownList and hits the button, it will display the lists of doctors available in the province, city and per particular schedule.
Check this sample. I have used SQLDatasource with SelectParameters for this example (you
can replace it with your own object datasource, custom binding etc.) SQLDataSource Select Parameters
The second dropdownlist automatically populates when the first dropdownlist is changed
On Button even I am just selecting the currently selected values of each dropdownlist (You can select your doctor list in the same way)
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Cascading DropDown.aspx.cs"
Inherits="Cascading_DropDown" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<title></title> </head> <body>
<form id="form1" runat="server">
<div>
<label>
Category:</label>
<asp:DropDownList ID="ddlCategories" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
DataSourceID="sdsCategory" DataTextField="CategoryName" DataValueField="CategoryID"
OnSelectedIndexChanged="ddlCategories_SelectedIndexChanged">
<asp:ListItem Text="-Select-" Value="" />
</asp:DropDownList>
<br />
<label>
Products:</label>
<asp:DropDownList ID="ddlProducts" runat="server" DataSourceID="sdsProducts" DataTextField="ProductName"
DataValueField="ProductID">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Search Prodcut" OnClick="Button1_Click" />
<asp:Label ID="lblSelectedValues" runat="server"></asp:Label>
</div>
<asp:SqlDataSource ID="sdsCategory" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] ORDER BY [CategoryName]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsProducts" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products] WHERE ([CategoryID] = #CategoryID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategories" Name="CategoryID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</form> </body> </html>
.CS
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlCategories.SelectedValue == "")
{
ddlProducts.Items.Clear();
ddlProducts.SelectedIndex = -1;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
lblSelectedValues.Text = "You selected Category:" + ddlCategories.SelectedItem.Text + " & prodcut:" + ddlProducts.SelectedItem.Text;
}
You can drop a gridview on form like Abel said & on your button click event, fetch each drop down list selected value & execute your query & databaind your gridview like you are already doing with your drop down lists.
All you essentially need to do is to place the controls in the ASPX page declaratively:
<asp:DropDownList id="ddlSche" runat="server" />
You can calculate the results in the Page_Load using ddlSched.SelectedValue and similar methods.
Essentially, you use the button's onclick handler for this type of thing:. But since you already have a SelectedIndexChanged event, it seems that you're on the right track. It's fired when the user postbacks the page and the index was changed (or, in other words, the user selected something else than the current selection in the DropDownList).

Categories