如何在网格内逐个显示逗号分隔值 [英] how to display comma seperated values one by one inside a grid
本文介绍了如何在网格内逐个显示逗号分隔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据网格,在网格中我有五列。在一列中,我显示的是逗号分隔的值,这些值是未组织的。gridview类似于
I have a datagrid and inside the grid I have five columns. In one column, I am displaying comma seperated values which are unOrganized.the gridview is like
Col1 Col2 Col3 Col4 Col5
1 a [acvdfvd], [dfasfsd 20 10
dfdfs],[sdfdsf][sadsa
fsfesf],[adsdas],
[dsfsdfdf],[dfss]
2 b " 30 20
现在,我想显示这样的值,
Now, I want to show the values like this,
Col1 Col2 Col3 Col4 Col5
1 a [acvdfvd], 20 10
[dfasfsddfdfs],
[sdfdsf],
[sadsafsfesf],
[cxadsdas],
[dsfsdfdf],
[dfss]
2 b " 30 20
这至少是可以理解的。 Pleace帮助我如何做到这一点。谢谢。
This will atleast be understandable. Pleace help me on how to do it. Thanks.
推荐答案
您可以使用第3列的嵌套网格来显示逗号分隔值。
添加gridview属性:onrowdatabound =parent_RowDataBound到父gridview
You can use nested grid for col 3 to display comma separated values.
Add gridview property : onrowdatabound="parent_RowDataBound" to parent gridview
protected void parent_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Bind child gridview here...
}
}
试试这个..
Try this out..
通过以下链接...
http://stackoverflow.com/questions/14456826/c-line-break-instead-of-comma-separated-valu es-in-gridview [ ^ ]
使用Literal代码中的代码中的
go through following link...
http://stackoverflow.com/questions/14456826/c-line-break-instead-of-comma-separated-values-in-gridview[^]
in that code in Literal tag use
Text=''<%# string.Join("<br />,", Eval("Values").ToString().Split(new []{","},StringSplitOptions.None)) %>''
因为你想要单独的值,并且它们在下一行有值,但是从值中删除..
becouse u want separate values by , and they have values on next line but , is removed from values..
通过使用Repeater我们很容易实现这一点。
1)使用[Col1,Col2,Col3,Col4,Col5]列创建MainRepeater和主数据。
2)在Col3内部插入一个名为splitRepeater的嵌套Repeater。
3)编写MainRepeater和Split的ItemDatabound事件Col3的值与逗号(,)和查找SplitRepeater并绑定分割字符串数组。
By using Repeater we can easily achieve this.
1) Build MainRepeater with your Main Data with the columns of [Col1,Col2,Col3,Col4,Col5].
2) Inside of Col3 ,Insert one nested Repeater called splitRepeater.
3) Write a ItemDatabound event of MainRepeater and Split the the Value of Col3 with Comma(,) and Find SplitRepeater and Bind the Array of Splitted String.
这篇关于如何在网格内逐个显示逗号分隔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文