Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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........
Posted
Comments
Kenneth Haugland 30-Jul-12 5:13am    
use a for loop and get the chars:)

Hi,
It's so simple. Convert it in array and set the data-source of the grid to array.
Use this:
HTML:
ASP.NET
<asp:gridview id="gvEx" runat="server" xmlns:asp="#unknown" />

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




All the best.
--Amit
 
Share this answer
 
Comments
Raje_ 31-Jul-12 0:10am    
nice & short, my +5
_Amy 31-Jul-12 0:12am    
Thank you Rajesh. :)
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;

C#
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();
 
Share this answer
 
Try In this format,

C#
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();
}
 
Share this answer
 
v2
Comments
_Amy 30-Jul-12 23:45pm    
Why should e loop through? We can directly convert it into char array. Use ToCharArray().
C#
string str = "hiiiiiiiiiiiiiiii";
        GridView1.DataSource = str;
        GridView1.DataBind();


this is working well..............
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900