如何获得列表框选定的值 [英] How to get listbox selected value

查看:93
本文介绍了如何获得列表框选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想通过使用listbox_Indexchanged事件获取列表框选定的值,但是我无法获得选定的索引或选定的值.请帮帮我.

这是我到目前为止编写的代码(dt1是一个DataTable).

Hi Iam trying to get listbox selected value by using thelistbox_Indexchanged event, but I am unable to get the selected index or selected value. Please help me out.

Here''s the code I''ve written so far (dt1 is a DataTable).

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        dt1.Clear();
        dt1 = g1.Getusers();
        for (i = 0; i < dt1.Rows.Count; i++)
        {
            if (ListBox1.SelectedValue.ToString() == dt1.Rows[i][1])
            {
                TextBox1.Text = dt1.Rows[i][1].ToString();
                TextBox2.Text = dt1.Rows[i][2].ToString();
                DropDownList1.SelectedValue = dt1.Rows[i][3].ToString();
            }
        }
    }



谢谢.



thanks.

推荐答案

好,您正在比较:
ListBox1.SelectedValue.ToString() == dt1.Rows[i][1]
好像您没有使用DEBUGGER并看到过这些值.在我看来,这种比较是不正确的.

请调试并查看是否选择了这些值.

还有一件事,请确保在此selectedindexchange事件触发之前,不要将LitBox1与数据集重新绑定.
Well, you are comparing:
ListBox1.SelectedValue.ToString() == dt1.Rows[i][1]
Looks like you have not used DEBUGGER and seen the values. it looks to me that the comparison is not correct.

Please debug and see if the values are selected.

One more thing, do make sure that you are not re-binding the LitBox1 with the dataset before this selectedindexchange event fires.


这篇关于如何获得列表框选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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