停止下拉列表自动刷新 [英] to stop drop down list auto refresh

查看:64
本文介绍了停止下拉列表自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在从数据库访问值以填充下拉列表.
现在,当我单击显示"按钮或第二种方式时,我选择列表的索引.该页面将变为自动刷新,并且列表的第一个值选择自动.每次仅针对下拉列表中的第一个值显示结果.我该怎么解决...

Hi,
I am accessing values from the database to fill the drop down list.
now when i click on the show button or if second way i select the index of the list. the page becomes auto refresh and the first value of the list selects auto. the result displayed only for the first value in the drop down list each time. how i could solve it......

protected void ddlNames_SelectedIndexChanged(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        con = new SqlConnection("Data Source=KADSERVER;Initial Catalog=Kadsyscon_temp;User ID=sa;Password=syscon1234");
        con.Open();
        //DataSet ds = new DataSet();
        dtLogin = new DataTable();
        string str1 = "select Date,InTime ,OutTime from EmpAttendanceDetails WHERE EID=" + ddlNames.SelectedValue.ToString();
        Command = new SqlCommand(str1, con);
        Command.CommandType = CommandType.Text;
        SqlDataAdapter da = new SqlDataAdapter(Command);
        da.Fill(dtLogin);

        gvDetails.DataSource = dtLogin;
        gvDetails.DataBind();
    }
}


这是我写的代码.我在按钮单击上使用了相同的代码,但问题仍然存在....


this is the code i have written. and i used the same code on the button click but the problem persists....

推荐答案

实际上,您两次使用相同的代码是很糟糕的设计,实际上,所有这些都是不好的.每当有人单击按钮时,就调用数据库.为什么需要这样做?基本上,每当有人选择某项内容时,您便会重设列表,当然,这也会重设选择项.
The fact you use the same code twice, is terrible design, in fact, all of this is bad. You call the DB every time someone clicks a button. Why do you need to do that ? You basically reset the list every time someone selects something, which will, of course, reset the selection.


我刚才犯了错误.我在下拉列表的selectedindexchanged上使用了!ispostback",还尝试了单击显示按钮.但后来我在填写下拉列表时在页面加载中使用了它.它解决了我的问题.现在,下拉列表不会刷新,而是保留在索引上(无论选择哪个).谢谢大家对我的帮助!
I have just got my mistake. I was using the "!ispostback" on the selectedindexchanged of dropdownlist and also tried on show button click. but then i used it on page load at the time of filling the dropdown list. and it solved my problem. now the drop down list do not refreshes and remains on the index whichever is selected. thanks for all to help me!!!


这篇关于停止下拉列表自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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