Removing extra white space from the GridView template

I'm trying to figure out how to get rid of some of the whitespace that Visual Studio and gridview have. It was a little annoying, which bothered me.

If I have well formatted html inside.

   <asp:Literal ID="myLit" runat="server" /> 


it produces the following result in Firebug -

<td> Text </td>


I understand that if I change my html formatting to the following, it works.

<ItemTemplate><asp:Literal ID="myLit" runat="server" /></ItemTemplate>


The problem is that Vs2010 and / or codemaid extension always returns it (which adds a space at the beginning)

      <asp:Literal ID="lblJson" runat="server" /></ItemTemplate>
<td> Text</td>


I had problems due to this extra space with some Jquery table sort plugins.
Is there a way to tell the gridview to trim extra whitespace from the html?

Thanks Alex


source to share

2 answers

Use the ItemDataBound event to capture the content control using FindControl and remove the whitespace.



If you get values ​​with spaces inside, you can remove them in the RowDataBound event

 myLit = e.Row.Cells[0].Text; 


and then use simple string manipulation to remove them


it could be that the alignment is not set to the left ...

Then in the column section where you are setting margins add this

ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"




All Articles