Click here to Skip to main content
13,097,012 members (32,210 online)

i m new in and i want 2 call a gridview by dropdownlist.

Rashid Choudhary asked:

Open original thread
i have a drop down list which have three entry.when i select every entry of dropdownlist then the data show into the code behind page is

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Net.Mail;
using System.IO;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
namespace AccountManagement
    public partial class Account : System.Web.UI.Page
        SqlConnection con;
       SqlDataAdapter da;
        SqlDataReader dr;
        //DataSet ds1;
       // String Sql;
        //int Count;
        DataTable dt;
        SqlCommand cmd;
        protected void Page_Load(object sender, EventArgs e)
            string s = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
            con = new SqlConnection(s);
            //if (!IsPostBack)
            //    bindgrid();
            //    bindlst();
        //protected void Button1_Click(object sender, EventArgs e)
        //    bindgrid();
        //    GridView1.Visible = true;
        public void bindgrid()
            cmd=new SqlCommand ("select distinct Fname,Lname from Client_registration_tbl",con);
            //ds1 = new DataSet();
            dr = cmd.ExecuteReader();
            GridView1.DataSource = dr;
            GridView1.Visible = true;
        public void bindlst()
            da = new SqlDataAdapter("select distinct Fname,Lname from Client_registration_tbl", con);
            dt = new DataTable();
            DropDownList1.DataSource = dt;
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            da = new SqlDataAdapter("select distinct Fname,Lname from Client_registration_tbl" + DropDownList1.SelectedItem.Text + "", con);
            dt = new DataTable();
            GridView1.DataSource = dt;
            //GridView1.Visible = true;


thanksss in advance
Tags: ASP.NET, Gridview, drop-down


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100