Click here to Skip to main content
12,999,081 members (50,089 online)
Rate this:
Please Sign up or sign in to vote.
i hv a button,dropdownlist,and gridview. and i want that when i select any option dropdownlist . then the releted data is show into gridview .i hv a problem that tha data show in gridview but gridview d'nt affect with the data list..
my code 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)
        //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;
           // bindgrid();
            //GridView1.Visible = true;

Posted 13-Sep-12 19:34pm
Updated 13-Sep-12 21:25pm
Vani Kulkarni 14-Sep-12 1:42am
You have already posted this question here[^].Please do not repost. Update your existing question using Improve Question.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

2 Options:
1. Use Dropdown selectedIndexchange event (with AutoPostback set to true) on server side to find the value selected in the dropdownlist. based on the value selected, get the data from database and display in a grid.
2. Use AJAX to fire a XMLHttpRequest/Callback/PageMethod from client side to server on drodown change and get the data back as a response which can be used to bind with the XML.

Try both and learn on.

Option 1 is straightforward. Option 2 needs knowledge on ways to interact with server form client, read here:
1. XMLHttpRequest[^]
2. Callback[^]
3. WebService call[^]
4. PageMethod[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 14 Sep 2012
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