How to use wrap for Gridview?

Posted by Oswaldlily under ASP.NET on 10/7/2011 | Points: 10 | Views : 17167 | Status : [Member] | Replies : 8
I have Gridview in design page
<asp:Gridview id="gv" runat="server"></asp:gridview>

Then I dynamically binded rows and columns through code..

I need to wrap my values in gridview if it go beyond larger values.

How to set wrap text.?




Responses

Posted by: SheoNarayan on: 10/7/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
You can wrap your GridView in the div and specify style for the div something like

<div style="width:200px;overflow:auto;">
<asp:Gridview id="gv" runat="server"></asp:gridview>
</div>

This will bring a scrollbar automatically when the GridView size increases 200px.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Walia_jagwinder on: 10/7/2011 [Member] Starter | Points: 25

Up
0
Down
Do you want to wrap the content of grid rows?

One person's data is another person's program.

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 10/7/2011 [Member] Starter | Points: 25

Up
0
Down
yes i need to wrap rows..means if it exceed to some limit,it need to break that row automaticlly

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 10/7/2011 [Member] Starter | Points: 25

Up
0
Down
@SheoNarayan

I m getting scroll bar while using ur code..
I don want scroll bar..i need to break that line which should happen automatically

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/7/2011 [Member] Starter | Points: 25

Up
0
Down
You are free to set this column property for gridview
ItemStyle-Wrap="true"

or
<ItemStyle Wrap="true" />


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Walia_jagwinder on: 10/7/2011 [Member] Starter | Points: 25

Up
0
Down
<ItemStyle Wrap="true" />

One person's data is another person's program.

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 10/7/2011 [Member] Starter | Points: 25

Up
0
Down
@Ndebata
I m not using columns and templatefield lik below to use item style...
<Columns>
<asp:TemplateField><ItemStyle Wrap="true" /></asp:TemplateField>
</Columns>


I just used <asp:gridview:.........></asp:gridview> ..and added my columns through linq query and binded..
In this case how wher to use wrap-text or wordbreak?

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/7/2011 [Member] Starter | Points: 25

Up
0
Down
You can use row databound event to handle this
on page load register this event
GridView2.RowDataBound += new GridViewRowEventHandler(GridView2_RowDataBound);

Then define this method
void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)

{
if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell item in e.Row.Cells)
{
item.Wrap = true;
item.Width = 100;
}
}
}


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response