gridview columns

F

Fritz the Cat

Hi I have a long column of data.
I'd like that to wrap into 5 columns, like a newspaper article

how to do?
thanks
 
E

Eliyahu Goldin

You need to split one column into 5 programmatically, put the result in a
datasource like a datatable and databind to the new datasource.
 
G

Guest

Hi,

If you need to bind your huge text content to some column in a data
control, then in that case, you cld possibly try this option.

Html source:

<asp:GridView ID="gvColWrap" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField HeaderText="Your Original contented"
DataField="contentOriginal" />
<asp:BoundField HeaderText="<td colspan=5>Your wraped contented</td>"
HtmlEncode="false" DataField="contentWraped" />
</Columns>
</asp:GridView>

The second column here splits the same huge text content on column one into
5 diffrent columns within the same column itself.

Code to bind data to control:

DataTable dt = new DataTable();
dt.Columns.Add("contentOriginal");
dt.Columns.Add("contentWraped");

DataRow dr = dt.NewRow();
dr[0] =" ------ Huge original text content ------";
dr[1] = "<td> huge content split 1 </td>" +
"<td> huge content split 2 </td>" +
"<td> huge content split 3 </td>" +
"<td> huge content split 4 </td>" +
"<td> huge content split 5 </td>";

dt.Rows.Add(dr);
gvColWrap.DataSource= dt;
gvColWrap.DataBind();

As long as you know where you need to split the text for your five
paragraphs, each of the split content has to be prefixed with "<td>" and
suffixed with "</td>".

the HTMLEncode property of this particular dataBoundField needs to be set to
false.
If you desire to have a header for this field that is as wide as all the 5
columns in that case, for the headertext prefix and suffix it with <td> and
</td> and use the colspan property as in the example above.

I hope this helps.

- Parvathy Padmanabhan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top