BigCap
asked on
Gridview - column widths
I have populated a gridview as follows
Protected Sub fillGrid()
Me.dsRequestDetail.Connect ionString = Me.strConnectionString
Me.dsRequestDetail.SelectC ommandType = SqlDataSourceCommandType.S toredProce dure
Me.dsRequestDetail.SelectC ommand = "gw_GetRequestDetailByRequ estId"
Me.dsRequestDetail.SelectP arameters. Clear()
Me.dsRequestDetail.SelectP arameters. Add("idVal ue", requestNo)
Me.gvRequestDetail.DataSou rce = Me.dsRequestDetail
'Me.gvRequestDetail.AutoGe nerateEdit Button = True
'Me.gvRequestDetail.AutoGe nerateDele teButton = True
Me.gvRequestDetail.DataBin d()
Me.gvRequestDetail.Columns (0).ItemSt yle.Width = 100
Me.gvRequestDetail.Columns (1).ItemSt yle.Width = 200
End Sub
It works, with the exception of the last 2 width statements. the 2nd line gives an error and says the column I am using is greater than number of columns.
Help!!!
Also, how do you make a column be right justified rather than left, and can the column titles be omitted?
Thanks
Protected Sub fillGrid()
Me.dsRequestDetail.Connect
Me.dsRequestDetail.SelectC
Me.dsRequestDetail.SelectC
Me.dsRequestDetail.SelectP
Me.dsRequestDetail.SelectP
Me.gvRequestDetail.DataSou
'Me.gvRequestDetail.AutoGe
'Me.gvRequestDetail.AutoGe
Me.gvRequestDetail.DataBin
Me.gvRequestDetail.Columns
Me.gvRequestDetail.Columns
End Sub
It works, with the exception of the last 2 width statements. the 2nd line gives an error and says the column I am using is greater than number of columns.
Help!!!
Also, how do you make a column be right justified rather than left, and can the column titles be omitted?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I actually did it a different way. I used AutoGenerateColumns="False " on the gridview and then populated each column separately.
<asp:BoundField DataField="Job Ref" ItemStyle-Width="120" HeaderText="" />
<asp:BoundField DataField="Job Ref" ItemStyle-Width="120" HeaderText="" />
Hi
Glad you got your solution.
btw. i first now recognised it was asp.net -:) by seeing this line: Me.gvRequestDetail.DataBin d()
though when asking questions, you should preliminary state which ver of visual studio 2003,2005 and if it is vb.net or asp.net ect...
vbturbo
And here is everything you need to know about datagridview in asp.net 2.0
http://msdn2.microsoft.com/en-us/library/aa479339.aspx
Glad you got your solution.
btw. i first now recognised it was asp.net -:) by seeing this line: Me.gvRequestDetail.DataBin
though when asking questions, you should preliminary state which ver of visual studio 2003,2005 and if it is vb.net or asp.net ect...
vbturbo
And here is everything you need to know about datagridview in asp.net 2.0
http://msdn2.microsoft.com/en-us/library/aa479339.aspx
Me.gvRequestDetail.Columns
Me.gvRequestDetail.Columns
to get the correct amount of column's count
Dim x As Integer = Me.gvRequestDetail.Columns
vbturbo