Gridview Column width
-
I have been battling with setting gridview column width. Can some one help me out? I have a gridview that is bound to a datatable. Im using a session object as the datasource to my datatable and i want the gridview column width to be set to some value. Below are my various trial Protected Sub grdDetails_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdDetails.RowDataBound 'If e.Row.RowType = DataControlRowType.Header Then ' 'If e.Row.RowType = DataControlRowType.DataRow Then ' 'e.Row.Cells(0).Width = New Unit(1400, UnitType.Pixel) ' 'e.Row.Cells(1).Width = CInt(Server.HtmlDecode(2400)) ' e.Row.Cells(0).Attributes.Add("style", "width: 100px;") ' e.Row.Cells(1).Attributes.Add("style", "width: 100px;") 'End If 'grdDetails.Columns(1).ItemStyle.Width = CInt(Server.HtmlDecode(1400)) 'grdDetails.Columns(2).ItemStyle.Width = CInt(Server.HtmlDecode(2400)) If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Cells(0).Text = Date.Parse(e.Row.Cells(0).Text).ToString("d") 'format the numeric values For j As Integer = 3 To 5 e.Row.Cells(j).CssClass = "ralign" 'Amount Col e.Row.Cells(j).Text = Decimal.Parse(e.Row.Cells(j).Text).ToString("n") Next 'ElseIf e.Row.RowType = DataControlRowType.Footer Then ' 'display summary data in the appropriate cell ' e.Row.Cells(4).Text = "Total :" ' e.Row.Cells(5).Text = GetTotal().ToString("n") End If End Sub any help will be appreciated
-
I have been battling with setting gridview column width. Can some one help me out? I have a gridview that is bound to a datatable. Im using a session object as the datasource to my datatable and i want the gridview column width to be set to some value. Below are my various trial Protected Sub grdDetails_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdDetails.RowDataBound 'If e.Row.RowType = DataControlRowType.Header Then ' 'If e.Row.RowType = DataControlRowType.DataRow Then ' 'e.Row.Cells(0).Width = New Unit(1400, UnitType.Pixel) ' 'e.Row.Cells(1).Width = CInt(Server.HtmlDecode(2400)) ' e.Row.Cells(0).Attributes.Add("style", "width: 100px;") ' e.Row.Cells(1).Attributes.Add("style", "width: 100px;") 'End If 'grdDetails.Columns(1).ItemStyle.Width = CInt(Server.HtmlDecode(1400)) 'grdDetails.Columns(2).ItemStyle.Width = CInt(Server.HtmlDecode(2400)) If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Cells(0).Text = Date.Parse(e.Row.Cells(0).Text).ToString("d") 'format the numeric values For j As Integer = 3 To 5 e.Row.Cells(j).CssClass = "ralign" 'Amount Col e.Row.Cells(j).Text = Decimal.Parse(e.Row.Cells(j).Text).ToString("n") Next 'ElseIf e.Row.RowType = DataControlRowType.Footer Then ' 'display summary data in the appropriate cell ' e.Row.Cells(4).Text = "Total :" ' e.Row.Cells(5).Text = GetTotal().ToString("n") End If End Sub any help will be appreciated
-
Hi dear, First u tell me in yr grid AutoGenerateColumn is set to true or false?? regards,
Rana Krishnraj
-
That means u have to right the code like this : Note: below code is exa. purpose only.
<asp:gridview....
<Columns>
<asp:BoundColumn DataField="tid" HeaderStyle-Width="5%" HeaderText="Id" >
<ItemStyle Width="5%" />
</asp:BoundColumn>
<asp:BoundColumn DataField="tName" HeaderStyle-Width="15%" HeaderText="Keywords" ReadOnly="True">
<ItemStyle Width="15%" />
</Columns>Hope u get an idea....... best of luck :) regards,
Rana Krishnraj
-
That means u have to right the code like this : Note: below code is exa. purpose only.
<asp:gridview....
<Columns>
<asp:BoundColumn DataField="tid" HeaderStyle-Width="5%" HeaderText="Id" >
<ItemStyle Width="5%" />
</asp:BoundColumn>
<asp:BoundColumn DataField="tName" HeaderStyle-Width="15%" HeaderText="Keywords" ReadOnly="True">
<ItemStyle Width="15%" />
</Columns>Hope u get an idea....... best of luck :) regards,
Rana Krishnraj
-
its not working yet. there is no asp:BoundColumn. I used asp:BoundField yet its not working