Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
        {
          

        }

        protected void drplist_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectvalue = (((DropDownList)sender).SelectedValue).ToString();

                SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
                try
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = cnn;
                    cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = selectvalue;
                    cmd.CommandText = "select * from tbl_Registration where Email=@Email";
                    
                    cmd.CommandType = CommandType.Text;
                    cnn.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    
                   GridView1.DataSource = reader;
                  GridView1.DataBind();

                    cnn.Close();
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    if (cnn.State == ConnectionState.Open)
                    {
                        cnn.Close();
                    }
                }
                finally
                {
                    if (cnn.State == ConnectionState.Open)
                    {
                        cnn.Close();
                    }
                }

            }
Posted
Updated 16-Oct-13 23:48pm
v2
Comments
Zafar Sultan 17-Oct-13 5:55am    
Usually a gridview is used to display tabular data whereas a label is used to show text. Gridview offers a number of events to take benefit of whereas a label is limited to presentation purpose only. Gridview is used to present data in repeated form whereas a label is generally static. There is a huge difference between these two controls. You can select either depending upon your requirements. What exactly is it that is making you bound with label only?

1 solution

are you trying to bind all the details only to one label or else one particular field to the label.
 
Share this answer
 
v2
Comments
Member 10184990 17-Oct-13 6:38am    
i have 10 coloum
NagarajDJ 17-Oct-13 6:47am    
i think, you are getting 10 results by matching mail id yes ? If yes, then what is the need of displaying in one label if you are thinking of light weight controls then you can use repeater instead of grid view if this is also not suits to you then i have solution to your problem

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900