Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Format 2

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
how can you format a databound column in a datagrid after you converted it to a template? I can set the settings to what I want and during run time it will format, in design view the Databound section for each template I cannot adjust the width..

Thanks in advance.

 
Getting datagrids to display your desired widths can be frustrating.

Try: ItemStyle-Width="35" or HeaderStyle-Width="35"
The datagrid is a html table so setting the header width to 35 should be no different then setting each item to 35.
So why it there both? No sure.

If you don't want your data to wrap under any circumstances then use ItemStyle-Wrap="False"

If you do not want your cells to scrunch no matter what then you can force it's width.
Use ShowFooter=true on the grid and use the footertemplate shown below

<ASP:TEMPLATECOLUMN ItemStyle-CssClass="DataGridItem" ItemStyle-Width="300">
<ITEMTEMPLATE>
<ASP:LINKBUTTON id="butEdit" runat="server" CommandName="edit" >edit</ASP:LINKBUTTON>
</ITEMTEMPLATE>
<FooterTemplate>
<img src="images/spacer.gif" width="300" height="1">
</FooterTemplate>
</ASP:TEMPLATECOLUMN>
 
You can also set a cell width in the ItemCreated event of the DataGrid e.g.
Code:
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated

     e.Item.Cells(0).Width = New Unit(300, System.Web.UI.WebControls.UnitType.Pixel)

End Sub

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top