C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to set Datagrid Column width


Posted Date: 30 Apr 2004    Resource Type: Articles    Category: Web Applications

Posted By: ManojRajan       Member Level: Gold
Rating:     Points: 6



Datagrid has lot many default functionalities that allow you to simple mention the data source and bind it. The datagrid itself formats the appearance of the data. The default column width is set according to the length of the data displayed in it. However some times you may need to create a column and like to set few properties other than the default one. Microsoft recommends to define column whenever possible, which gives you a greater control over the properties. To turn off these properties set the Autogenerate property to false and manually define the columns. Now in the HTML view add columns and add a ItemStyle tag element and set the width property to the desired value. The same is possible with the width property of the column tag.


<asp:BoundColumn>
<ItemStyle Width="50px"></ItemStyle>
</asp:BoundColumn>




Responses

Author: Sajjad Haider    24 Jun 2004Member Level: Bronze   Points : 0
this is good simple but trickey


Author: Leland Usher    14 Jul 2004Member Level: Bronze   Points : 0
Hi, you could also use:
ItemStyle-Width="30%"
ItemStyle-Align="center"
CancelText="Cancel" EditText="Edit"
UpdateText="Save" />


Author: Leland Usher    14 Jul 2004Member Level: Bronze   Points : 0
Sorry, the "center" attribute doesn't work, any suggestions on how to ensure the contents are center aligned?

Thanks


Author: Iain Wood    01 Dec 2004Member Level: Bronze   Points : 0
Nice and useful but this stuff is part of it

alignment is done with HorizontalAlign and it works
these also work apparently

http://www.netomatix.com/DGItemStyles.aspx

BackColor
BorderColor
BorderStyle
VerticalAlign
BorderWidth
CssClass
Font
Width
ForeColor
Height
HorizontalAlign
Wrap


Author: Mathew    31 Jul 2008Member Level: Bronze   Points : 2
Description mentioned below helps to set the width of column in
datagrid fixed, wcich i had seen in most of the forum

hi ,..just try this in ur code behind

MyGrid.Attributes.Add("style", "table-layout:fixed");

then in HTML View of the gird if you have Label to Display the item in tiemdatbound give style="word-.... : break;"

*.... pls check that, i forgot that , then give column width it will work fine

mathew m mathew - malayalee mankan
<
Smile – It brings a difference...
Live – coz life is everything u have…!!!!!!!!!!
/>




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Width of Datagrid's column  .  Setting Datagrid column width  .  Set Datagrid Column width  .  How to set Datagrid Column width  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: ASP.NET Data Binding
Previous Resource: Format Date, numeric values in the DataGrid.
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

online optimum rewards

Contact Us    Privacy Policy    Terms Of Use