How to select between two columns amount values? using dropdown control.
Columns name is: from amount and end amount.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
magesh manavalanPosted Mar 24, 2012, 4:34 AM
Satyapriya NayakPosted Mar 24, 2012, 3:11 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="Paging_in_GridView.WebForm3" %>
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;
namespace Paging_in_GridView
{
public partial class WebForm3 : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
string str;
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.AutoPostBack = true;
DropDownList2.AutoPostBack = true;
SqlConnection con = new SqlConnection(connStr);
if (!IsPostBack)
{
DropDownList1.Items.Add("Choose fromamount");
con.Open();
str = "select * from Mobile";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList1.Items.Add(reader["fromamount"].ToString());
}
reader.Close();
con.Close();
DropDownList2.Items.Add("Choose endamount");
con.Open();
str = "select * from Mobile";
com = new SqlCommand(str, con);
SqlDataReader reader1 = com.ExecuteReader();
while (reader1.Read())
{
DropDownList2.Items.Add(reader1["endamount"].ToString());
}
reader1.Close();
con.Close();
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
try
{
con.Open();
str = "select model from Mobile where fromamount between '" + DropDownList1.SelectedItem.Text + "' and '" + DropDownList2.SelectedItem.Text + "' ";
com = new SqlCommand(str, con);
GridView1.DataSource = com.ExecuteReader();
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer