从具有XML列的表中填充ListBox [英] Populate ListBox from a table having a XML column

查看:118
本文介绍了从具有XML列的表中填充ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Folks,

遇到了一个问题,我从一天开始一直在努力.
我有一个包含varchar列和XML列的表.架构如下:

Hello Folks,

Have landed in a problem, which I am tryin to work since a day.
I have a table having a varchar column and a XML column.The schema is below:

create table dbo.StandardView(
Name varchar(50),
Fields xml)


我插入了一条记录,如下所示:


I inserted a record as below:

insert into dbo.StandardView values('Standard',N'<fieldname>FirstName,SecondName,ThirdName</fieldname>')



我需要使用实体填充列表框,如下所示:
名字
SecondName
ThirdName
填充编写的列表框的代码如下:



I need to populate a listbox with the entities as follows:
FirstName
SecondName
ThirdName
The code to populate the listbox written is as below:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateValues();
        }

    }
    public void PopulateValues()
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from dbo.StandardView", xconn);
        DataTable dt = new DataTable();
        da.Fill(dt);
        lstBox.DataSource = dt;
        lstBox.DataTextField = dt.Columns[1].ToString();
        lstBox.DataValueField = dt.Columns[1].ToString();
        lstBox.DataBind();

    }


上面的代码将整个xml列以字符串格式放入列表框中,并且非常明显.
我尝试了一些xmlserializer,deserializer和xmlreader东西,但无法相应地填充列表框.
专家请指导.
任何帮助或指针都应该非常有帮助..

-问候
Anurag


The above code puts the whole xml column in the listbox in a string format and its pretty evident.
I tried some xmlserializer,deserializer and xmlreader stuffs but wasn''t able to populate the listbox accordingly.
Experts please guide.
Any help or pointer should be pretty helpful..

-regards
Anurag

推荐答案

选中此


[^ ]
check this

http://social.msdn.microsoft.com/Forums/vstudio/en-US/3aa5523b-8693-4893-8508-eaa0b5f28ee3/convert-string-to-xml-and-bind-to-wpf-listbox[^]

also check this link as well


[^]


这篇关于从具有XML列的表中填充ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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