Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
i have a drop down list which have three entry.when i select every entry of dropdownlist then the data show into the gridview...my 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();
            //}
            con.Open();
        }
 
        //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();
            con.Open();
            dr = cmd.ExecuteReader();
            //da.Fill(ds1);
            GridView1.DataSource = dr;
            GridView1.DataBind();
            GridView1.Visible = true;
            con.Close();
 
        }
 
        public void bindlst()
        {
            da = new SqlDataAdapter("select distinct Fname,Lname from Client_registration_tbl", con);
            dt = new DataTable();
            da.Fill(dt);
            DropDownList1.DataSource = dt;
            DropDownList1.DataBind();
        }
        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();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
           
            bindgrid();
            bindlst();
            //GridView1.Visible = true;
        }
 
      
 

    }
}
thanksss in advance
Posted 13-Sep-12 22:19pm
Edited 13-Sep-12 22:20pm
__TR__28.9K
v2
Comments
cagdas0606 at 14-Sep-12 4:42am
   
and check your !postback situation, actually it should not run on formar way, you can use this and improve it day by day, by yourself
 
protected void Page_Load(object sender, EventArgs e)
{
if (Session["name"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
 
if (Page.IsPostBack)
{
gridwhateverelse.RowCommand +=gridwhateverelse_RowCommand;
return;
}
}
}

1 solution

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

Solution 1

you can do this via RowDataBound event, take a look at the RowDataBound events, do a research.i can explain something for you: click on your gridview and then click to the properties(which is formally on the right bottom of your project page), after click the thunder image(events) and find RowCommand,rowDeleting,rowdatabound fields and learn how these fields trigger your project. You can also search this: HiddenField operations on asp.net,c#
 
protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownListPermission");
ddl.DataSource = new DB().FillDataTable(" select bla bla "),surname) as name ORDER BY 2");
ddl.DataBind();
HiddenField authorized = (HiddenField)e.Row.FindControl("HiddenFieldauthorized");
ddl.SelectedValue = authorized.Value;
}
}
 
as well as this code is your answer
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 839
1 OriginalGriff 400
2 CPallini 275
3 George Jonsson 191
4 Richard Deeming 145
0 OriginalGriff 5,450
1 Sergey Alexandrovich Kryukov 4,532
2 CPallini 4,500
3 George Jonsson 3,102
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 14 Sep 2012
Copyright © CodeProject, 1999-2014
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