English 中文(简体)
如何获得GridView中囚室固定面积(特别是宽度)?
原标题:How to get fixed size (especially the width) of the cell in the GridView?
  • 时间:2012-01-16 05:33:00
  •  标签:
  • asp.net
  • css

I have a GridView that has different width of different cells in its Header. I want to get specific size of each cell since I have a scroll bar from left to right. What I have up to now is what the following:

“entergraph

And what I want is to have something like the following: enter image description here

表格的风格是:

<style type="text/css">

        .fixedColumn .fixedTable td
        {
            color: #FFFFFF;
            background-color: #5097d1;
            font-size: 14px;
            font-weight: normal;
        }

        .fixedHead td, .fixedFoot td
        {
            color: #FFFFFF;
            /*background-color: #5097d1;*/
            font-size: 14px;
            font-weight: normal;
            padding: 5px;
            border: 1px solid #187BAF;
            width: 600px;
        }
        .fixedTable td
        {
            font-size: 10pt;
            background-color: #FFFFFF;
            padding: 5px;
            /*text-align: left;*/
            border: 1px solid #CEE7FF;
        }
    </style>

EDIT: I used the following code:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if ((e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.DataRow))
           {     
             foreach (TableCell c in e.Row.Cells){
                    c.Wrap=true; 

                    c.Width = Unit.Percentage(100);
             }
           }
}

And the header are changed a little bit and I don t know why as shown below: enter image description here

问题回答

更好的选择是使用皮肤 file,可以帮助你。 http://msdn.microsoft.com/en-us/library/a479342.aspx” rel=“nofollow” http://msdn.microsoft.com/en-us/library/a479342.aspx

您可使用Grudview RowDataBound方法,具体指明每个牢房的宽度。

protected void gridview_RowDataBound(object sender, GridViewRowEventArgs)
{
  if ((e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.DataRow))
   {     
            e.Row.Cells[yourCellIndex].Wrap=true; 

           e.Row.Cells[yourCellIndex].Width = Unit.Percentage(% value);

   }
}

并且,如果你使用“单位:百分比”方法,确保所有牢房的总宽度应为100%。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签