My Doubt?
How to do that?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Mar 23, 2012, 10:59 PM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 23, 2012, 11:13 PM EDT
<%@ 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
Sam HobbsRank #107 · 20.5K reputationPosted Mar 23, 2012, 11:26 PM EDT