Click to See Complete Forum and Search --> : Why can't I set the width of a datagrid ?


Robert Chu
09-20-2006, 02:46 AM
<td rowspan = "4" valign = "top" width = "10%">

<ASP:DataGrid id="MyDataGrid" runat="server"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
Width="40"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="False"
DataKeyField="VoxNo"
OnDeleteCommand="MyDataGrid_Delete">

<Columns>
<asp:ButtonColumn HeaderText = "Delete" Text="Delete" CommandName="Delete"/>
<asp:BoundColumn HeaderText = "VoxNo" DataField = "VoxNo" ReadOnly = "True" />
<asp:BoundColumn HeaderText = "VoxName" DataField = "VoxName" ReadOnly = "True" />
<asp:BoundColumn HeaderText = "VoxMemo" DataField = "VoxMemo" ReadOnly = "True" />
</Columns>
</ASP:DataGrid>

</td>

sirpelidor
09-20-2006, 11:42 AM
1) try not to put a table (datagrid) within another table
2) use CSS to align and position your controls (for portable and cross browser reason)
3) once you take the datagrid out of the table template, this is what I would do to control the width of the datagrid:


<
ASPataGrid id="MyDataGrid" runat="server"
AutoGenerateColumns="False"
DataKeyField="VoxNo"
OnDeleteCommand="MyDataGrid_Delete"
class="myDgStyle"
>


inside your head tag, insert CSS style attritbute...

<style>
/*example for width control */
table.MyDgStyle{
width:500px;
}
</style>


for details on how to make your .NET-controls cross browser, consult CSS.