Click here to Skip to main content
15,846,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WCF Service which returns a dataset to the web client. The client then uses the passed dataset as the source for it's Gridview display. However rather than just allowing the default columns widths to be applied I want to be able to control the width of each column at the time the grid is being built. This might be achieved by a comma delimited string (eg 20,100,50,50,10) where each number represents the number of pixels in the corresponding column (col1=20 pixels, Col2=100 pixels, Col3=50 pixels etc..)

Is it possible to do this and if so can someone explain how and possibly give me an example ?


What I have tried:

Searching the web,
experts exchange
Updated 31-May-16 14:20pm

1 solution

If you are using TemplateFields & Binding in your .aspx file you can control the column width using the following;
<headerstyle width="10%" />
<asp:label id="lblField" runat="server" text="<%# DataBinder.Eval(Container, "DataItem.ColumnName") %>"><asp:label>

If you are doing it in the code behind it is simply a matter of getting the grid view after binding & setting the column widths as required

Kind Regards
Share this answer

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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