Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually , i have one dropdown , on selectindexchange of drowndown value of table get change , but next time when i again selectindexchange of dropdown previous value remain in table , i am using autopostback to refresh dropdown

What I have tried:

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        string query = "select attenday , slot , present from attendance where name = '" + DropDownList1.Text + "'";

        DataTable dtAdmin = new DataTable();
        SqlDataAdapter da;
        da = new SqlDataAdapter(query, con);
        da.Fill(dtAdmin);
        if (dtAdmin.Rows.Count > 0)
           {
                SqlCommand cmd = new SqlCommand(query, con);
                 SqlDataReader dbr;
              
                    con.Open();
                    dbr = cmd.ExecuteReader();
                    while (dbr.Read())
                    {
                        string attenday = (string)dbr["attenday"].ToString();
                        string slot = (string)dbr["slot"].ToString();
                        string presentday = (string)dbr["present"].ToString();

                       
                        if (attenday == "1")
                        {
                            DropDownList2.Text = slot;
                            Label1.Text = presentday;
                        }

                        else if (attenday == "2")
                        {
                            DropDownList3.Text = slot;
                            Label3.Text = presentday;
                        }

                        else if (attenday == "3")
                        {
                            DropDownList4.Text = slot;
                            Label5.Text = presentday;
                        }

                        else if (attenday == "4")
                        {
                            DropDownList5.Text = slot;
                            Label7.Text = presentday;
                        }

                        else if (attenday == "5")
                        {
                            DropDownList6.Text = slot;
                            Label9.Text = presentday;
                        }

                        else if (attenday == "6")
                        {
                            DropDownList7.Text = slot;
                            Label2.Text = presentday;
                        }


                        else if (attenday == "7")
                        {
                            DropDownList8.Text = slot;
                            Label4.Text = presentday;
                        }


                        else if (attenday == "8")
                        {
                            DropDownList9.Text = slot;
                            Label6.Text = presentday;
                        }


                        else if (attenday == "9")
                        {
                            DropDownList10.Text = slot;
                            Label8.Text = presentday;
                        }

                        else if (attenday == "10")
                        {
                            DropDownList11.Text = slot;
                            Label10.Text = presentday;
                        }
                      

                      
                    }

                    dbr.Close();
Posted
Updated 10-Jan-18 2:35am
Comments
Richard Deeming 10-Jan-18 12:36pm    
Also, do yourself a favour and give your controls meaningful IDs, rather than just accepting the default ones suggested by Visual Studio.

You might remember which day Label6 refers to now, but when you come back to edit your code in six months, you'll be cursing the person who wrote the code!
Karthik_Mahalingam 10-Jan-18 22:28pm    
well said!👍

1 solution

if you are calling this Table Bind function on Page Load then Write your function calling inside:

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
       // Call Your Function
    }
}
 
Share this answer
 
Comments
ADI@345 11-Jan-18 6:37am    
I am able to show record in table on dropdown index change but again i select another value in dropdown, previous value remain in table, i need to remove previous value.

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