panareto
asked on
Data Grid Column Width
I have a Data Grid that is populated Dynamically via a DataTable. The AutoGenerateColumns attribute is set to true because the i retreive the data from a database table. The DataGrid Produces 4 columns and i want the 2nd one to have a different width than the others. I tried to set it via Datagrid.Columns(1).ItemSt yle.Width = ...
but it doesnt work as i thing the column collection is not populated at all...
DataGrid.Columns.Count results 0....
Can anybody help please?
but it doesnt work as i thing the column collection is not populated at all...
DataGrid.Columns.Count results 0....
Can anybody help please?
Change column width after binding,
DataGrid1.DataSource = GetRecords();
DataGrid1.DataBind();
// change 2th column width to 60 pixel
DataGrid1.Columns[1].ItemS tyle.Width = new Unit("60 px");
DataGrid1.DataSource = GetRecords();
DataGrid1.DataBind();
// change 2th column width to 60 pixel
DataGrid1.Columns[1].ItemS
ASKER
Pro_DataGrid2.ShowHeader=" True"
Pro_DataGrid2.DataSource = Pro_Table2
Pro_DataGrid2.DataBind()
Pro_DataGrid2.Columns(1).I temStyle.W idth = Unit.Pixel(300)
Pro_Table2.Columns.count //results 4
Pro_DataGrid2.Columns.coun t //results 0
and the Pro_DataGrid2.Columns(1).I temStyle.W idth = Unit.Pixel(300)
results error...System.ArgumentOut OfRangeExc eption: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Pro_DataGrid2.DataSource = Pro_Table2
Pro_DataGrid2.DataBind()
Pro_DataGrid2.Columns(1).I
Pro_Table2.Columns.count //results 4
Pro_DataGrid2.Columns.coun
and the Pro_DataGrid2.Columns(1).I
results error...System.ArgumentOut
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
--------------------------
private void DataGrid1_ItemDataBound(ob
{
switch ( e.Item.ItemType )
{
case ListItemType.Header:
e.Item.Cells[0].Width = 70; // This will set 1st Column to width 70
break;
}
}
--------------------------
-tushar