G
Guest
Greetings,
I have a gridview which is sitting on a multi view control (witin a view),
and it is bound to a dataset which I dynamically apply to the control within
asp.net page. The problem is that I can't seem to resize my dataview's
columns which are auto generated. Is there a way to do this? I have tried
several different things, but I can't seem to get at the column collection to
change the widths?
MY development environment
- System XP Pro, using Visual Studio 2005.
- A content page which hosts a multiview control with a single view in the
control.
- The single view hosts a view with my gridview on it which is dynamically
linked to
the datagrid control.
- Dataview control is bound to a dataset which has been dynamically built.
// A dataset is built, and the gridview is set to auto create the columns.
DataSet data = CreateDataSetForUse();
GridView1.DataSource = data;
GridView1.DataMember = "MyDataSet";
GridView1.DataBind();
The data is correct, and the columns are appearing correctly, BUT
I can't seem to resize the columns.
I have tried overriding the RowDataBound call like the sample in msdn shows,
but I am not getting access to the column collection.
(ie
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
System.Data.DataRowView drv = (System.Data.DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (drv != null)
{
/*
widestData = catNameLen;
GridView1.Columns[2].ItemStyle.Width =
widestData * 30;
GridView1.Columns[2].ItemStyle.Wrap = false;
*/
// Always returns 9, for my bound columns
int count = drv.Row.Table.Columns.Count;
// Never returns anything but 0?
count = GridView1.Columns.Count; }
}
Any ideas on how I can resize the columns with a databound gridview?
Thanks in advance for any suggestions!
I have a gridview which is sitting on a multi view control (witin a view),
and it is bound to a dataset which I dynamically apply to the control within
asp.net page. The problem is that I can't seem to resize my dataview's
columns which are auto generated. Is there a way to do this? I have tried
several different things, but I can't seem to get at the column collection to
change the widths?
MY development environment
- System XP Pro, using Visual Studio 2005.
- A content page which hosts a multiview control with a single view in the
control.
- The single view hosts a view with my gridview on it which is dynamically
linked to
the datagrid control.
- Dataview control is bound to a dataset which has been dynamically built.
// A dataset is built, and the gridview is set to auto create the columns.
DataSet data = CreateDataSetForUse();
GridView1.DataSource = data;
GridView1.DataMember = "MyDataSet";
GridView1.DataBind();
The data is correct, and the columns are appearing correctly, BUT
I can't seem to resize the columns.
I have tried overriding the RowDataBound call like the sample in msdn shows,
but I am not getting access to the column collection.
(ie
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
System.Data.DataRowView drv = (System.Data.DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (drv != null)
{
/*
widestData = catNameLen;
GridView1.Columns[2].ItemStyle.Width =
widestData * 30;
GridView1.Columns[2].ItemStyle.Wrap = false;
*/
// Always returns 9, for my bound columns
int count = drv.Row.Table.Columns.Count;
// Never returns anything but 0?
count = GridView1.Columns.Count; }
}
Any ideas on how I can resize the columns with a databound gridview?
Thanks in advance for any suggestions!