在GridView中显示字符串 [英] Display string in gridview

查看:76
本文介绍了在GridView中显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个字符串,如字符串abc ="Codeproject";
现在我必须在网格视图中以这种格式显示此字符串
c
o
d
e
...

那么我怎么能做到呢?
请帮助我........

Hi,
i have a string like string abc="Codeproject";
now i have to display this string in gridview like this format
c
o
d
e
...

so how cani acchivve this ?
pls help me........

推荐答案


太简单了.将其转换为数组并将网格的数据源设置为数组.
使用这个:
HTML:
Hi,
It''s so simple. Convert it in array and set the data-source of the grid to array.
Use this:
HTML:
<asp:gridview id="gvEx" runat="server" xmlns:asp="#unknown" />


代码:


Code:

string str = "Codeproject";
char[] arr = str.ToCharArray();
gvEx.DataSource = arr;
gvEx.DataBind();





祝一切顺利.
--Amit





All the best.
--Amit


一种方法是,可以使用arrayList保留拆分后的字符串,然后将arrayList分配为GridView的数据源.
为此,您必须包括以下内容:

使用System.Collections;

One way is, you can use the arrayList to hold the split-up string, and then assign the arrayList as the DataSource for the GridView.

For that you have to include the following:

using System.Collections;

string originalText = "CodeProject";
ArrayList arrayText = new ArrayList();
for (int loopIndex = 0; loopIndex < originalText.Length; loopIndex++)
{
    arrayText.Add(originalText[loopIndex].ToString());
}
GridView1.DataSource = arrayText;
GridView1.DataBind();


尝试以这种格式,

Try In this format,

char[] array = TextBox1.Text.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
    // Get character from array.
    char letter = array[i];
    // Display each letter.
    StringBuilder db = new StringBuilder();
    db.Append("<br />"+letter);
    Label1.Text += db.ToString();
}


这篇关于在GridView中显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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