C#检查列表框从数据库动态绑定并获取所选值 [英] C# checked list box dynamically binding from database and get the selected value

查看:53
本文介绍了C#检查列表框从数据库动态绑定并获取所选值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我正在寻找一个解决方案,我在下面给出了我的代码,当我在选中列表框中添加静态项目并选择一个项目我在消息框上获取项目就像一些列表框值但具有相同的代码当我从数据库值绑定检查列表框时我得到的消息框值是System.Data.DataRowView我该怎么做才能得到解决方案任何人帮助我



我尝试过:



hi i am looking for a solution i given my code below when i added static item on the checked list box and selecting a item i am getting the item on the message box is like "Some listbox value" But with the same code when i am binding checked list box from the database value i am getting the message box value is System.Data.DataRowView what should i do to get the solution anybody help me

What I have tried:

private void button1_Click(object sender, EventArgs e)
    {
        foreach (object s1 in ChGetQtnNumber.CheckedItems)
        {
            string getdetailofQtn = s1.ToString();
            MessageBox.Show(getdetailofQtn);
        }
    }

推荐答案

DataRow没有实现ToString,因为它无法分辨哪个单元格或卖出你想看看!因此,ToString调用默认的对象实现,该实现返回System.Data.DataRow类型的名称。

而不是使用ToString,从行中获取列数据:

DataRow does not implement ToString, because it can't tell which cell or sells you want to look at! As a result, ToString calls the default object implementation which returns the name of the type "System.Data.DataRow".
Instead of using ToString, get the column data from the row:
string getdetailofQtn = "";
DataRow dr = s1 as DataRow;
if (dr != null && dr.ItemArray.Length > 0)
   {
   getdetailofQtn = dr[0].ToString();
   }
else
   ...


这篇关于C#检查列表框从数据库动态绑定并获取所选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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