如何在C#中的dropdown selectindexchange上刷新表 [英] How to refresh table on dropdown selectindexchange in C#

查看:168
本文介绍了如何在C#中的dropdown selectindexchange上刷新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我有一个下拉列表,在selectindexchange的表的drowndown值得到更改,但下次当我再次选择下拉列表的下拉值时,表格中仍然保留下来值,我使用autopostback刷新下拉列表



我尝试了什么:



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();

推荐答案

如果你在Page Load上调用这个表绑定函数然后写你的函数调用里面:



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

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
       // Call Your Function
    }
}


这篇关于如何在C#中的dropdown selectindexchange上刷新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆