Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview Column width

Gridview Column width

Scheduled Pinned Locked Moved ASP.NET
designsysadminhelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aransiola
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • A aransiola

      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

      K Offline
      K Offline
      Krishnraj
      wrote on last edited by
      #2

      Hi dear, First u tell me in yr grid AutoGenerateColumn is set to true or false?? regards,

      Rana Krishnraj

      A 1 Reply Last reply
      0
      • K Krishnraj

        Hi dear, First u tell me in yr grid AutoGenerateColumn is set to true or false?? regards,

        Rana Krishnraj

        A Offline
        A Offline
        aransiola
        wrote on last edited by
        #3

        autogeneratecolumn is set to false

        K 1 Reply Last reply
        0
        • A aransiola

          autogeneratecolumn is set to false

          K Offline
          K Offline
          Krishnraj
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • K 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

            A Offline
            A Offline
            aransiola
            wrote on last edited by
            #5

            its not working yet. there is no asp:BoundColumn. I used asp:BoundField yet its not working

            R 1 Reply Last reply
            0
            • A aransiola

              its not working yet. there is no asp:BoundColumn. I used asp:BoundField yet its not working

              R Offline
              R Offline
              rupali_sd
              wrote on last edited by
              #6

              Try This on Page Load GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word") Roopali Gupta

              ad

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups