Mr_Shaw
asked on
Gridview column width.
Hi,
I am trying to increase the size of column in my gridview.
I have tried to use
Referral_Gridview.Columns[ 1].ItemSty le.Width = Unit.Pixel(100);
but i get the following error:
Index was out of range. Must be non-negative and less than the size of the collection.
For reasons too long to explain I am not binding my data using asp, but rather C#
Can anybody help.
I am trying to increase the size of column in my gridview.
I have tried to use
Referral_Gridview.Columns[
but i get the following error:
Index was out of range. Must be non-negative and less than the size of the collection.
For reasons too long to explain I am not binding my data using asp, but rather C#
Can anybody help.
Use (i) in place of [1]
ASKER
I only want to effect the width of column 1
try this gridProducts.Columns[1].He aderStyle. Width = 100;
ASKER
Nope..same error
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See whether your getting data to gridview?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
How do I check if there is an index in the column.
ASKER
I am not sure what the error means
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I am not really sure how to use the watch window.
Here is a screen shot of my watch window. Is it possible for you to mark on it where I have to look.
watch-window-screen-shot.bmp
Here is a screen shot of my watch window. Is it possible for you to mark on it where I have to look.
watch-window-screen-shot.bmp
Look at the Columns. Are there any Columns in the gridview?
ASKER
yes. my gridview is populated.... i just need to expand one of the columns.
Check whether the gridview has column collection by clicking '+' sign before Columns in watch window. If you then after binding keep the piece of code specified by Harry/dev
ASKER
hmm not sure... here is a screen shot for you to have a look.
Shall I put the piece of code specified by Harry/dev in the page load or on RowDataBound
watch-window-screen-shot-collect.bmp
Shall I put the piece of code specified by Harry/dev in the page load or on RowDataBound
watch-window-screen-shot-collect.bmp
Use Column index as 0 not 1
ASKER
Ok.. now error..
But how do i specify which column I want to change the width..
But how do i specify which column I want to change the width..
You can specify the column name or column index. your snapshot shows only one column. So index will be 0
dataGridView1.Columns[0].W idth = 100;
or
If (Referral_Gridview.Columns != null && Referral_Gridview.Columns. Count >0)
{
Referral_Gridview.Columns[ 0].ItemSty le.Width = Unit.Pixel(100);
}
as Harry/Dev said
dataGridView1.Columns[0].W
or
If (Referral_Gridview.Columns
{
Referral_Gridview.Columns[
}
as Harry/Dev said
ASKER
I have ten columns.
I am binding my data dynamically
example
gridview1.datasource = dataset;
gridveiw.databind();
I am binding my data dynamically
example
gridview1.datasource = dataset;
gridveiw.databind();
Specify Columnm name instead of index
If (Referral_Gridview.Columns != null && Referral_Gridview.Columns. Count >0)
{
Referral_Gridview.Columns[ "Col1"].It emStyle.Wi dth = Unit.Pixel(100);
}
If (Referral_Gridview.Columns
{
Referral_Gridview.Columns[
}
ASKER
it does not like me putting a string in place of an int
can you post your code?
ASKER
Referral_Gridview.Columns[ "Providers "].ItemSty le.Width = Unit.Pixel(100);
The Columns overload is an int not a string.
The Columns overload is an int not a string.
Can you post the part of code where you are binding data assigning col width
ASKER
Referral_Gridview.DataSour ce = DataSet1;
Referral_Gridview.DataBind ();
Referral_Gridview.Columns[ "Providers "].ItemSty le.Width = Unit.Pixel(100);
Referral_Gridview.DataBind
Referral_Gridview.Columns[
--> Referral_Gridview.DataSour ce = DataSet1;
Referral_Gridview.DataBind ();
Referral_Gridview.Columns[ "Providers "].ItemSty le.Width = Unit.Pixel(100);
At the arrowed point pls keep breakpoint and check the data in dataset
Referral_Gridview.DataBind
Referral_Gridview.Columns[
At the arrowed point pls keep breakpoint and check the data in dataset
ASKER
the syntax which you are suggesting will not work because Column[ ] requires a int overload not a string.
You can have index. thats fine. Look at the dataset and check whether do u have any data or not?
ASKER
the code which worked was
if (e.Row.RowType == DataControlRowType.DataRow )
{
e.Row.Cells[4].Width = 500;
}
if (e.Row.RowType == DataControlRowType.DataRow
{
e.Row.Cells[4].Width = 500;
}