日期:2014-05-18  浏览次数:20705 次

gridview动态表头,可以用百分比,但表格如何用百分比都对不齐,请问如何解决?
<div class="divGrid">
  <div class="headgrid">
  <div class="titleHeadgrid" style="width: 49px">
  序号</div>
  <div class="titleHeadgrid" style="width: 106px">
  物资编码</div>
  <div class="titleHeadgrid" style="width: 305px">
  物资名称</div>
  <div class="titleHeadgrid" style="width: 102px">
  计量单位</div>
  <div class="titleHeadgrid" style="width: 92px">
  数量</div>
  <div class="titleHeadgrid" style="width: 92px">
  单价</div>
  <div class="titleHeadgrid" style="width: 102px">
  金额</div>
  <div class="titleHeadgrid1" style="width: 122px">
  录入时间</div>
  <div class="titleHeadgrid1" style="width: 127px">
  备注</div>
  <div class="titleHeadgrid1" style="width: 72px">
  操作</div>
  </div>


上面的表头可以用百分比,但表格怎么用百分比都与上面的对不齐,哪位遇到过这类难题,,

------解决方案--------------------
可以设置绝对宽度
 #region //生成标题
protected void GvDate_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
DataTable RTb = (DataTable)ViewState["REASONTB"];
TableCellCollection tcHeader = e.Row.Cells;
//清除
tcHeader.Clear();
//重绘
tcHeader.Add(new TableHeaderCell());
tcHeader[0].Attributes.Add("rowspan", "2");//跨2行
tcHeader[0].Text = "年月";
tcHeader.Add(new TableHeaderCell());
tcHeader[1].Attributes.Add("rowspan", "2");//跨2行
tcHeader[1].Text = "着工数(K)";
tcHeader.Add(new TableHeaderCell());
tcHeader[2].Attributes.Add("rowspan", "2");//跨2行
tcHeader[2].Text = "内部异物(枚)";
tcHeader.Add(new TableHeaderCell());
tcHeader[3].Attributes.Add("rowspan", "2");//跨2行
tcHeader[3].Text = "不良率(ppm)";
tcHeader.Add(new TableHeaderCell());
tcHeader[4].Attributes.Add("colspan", RTb.Rows.Count.ToString());//跨2行
tcHeader[4].Text = "推定异常原因(发生个数)</th></tr><tr>";
for (int i = 5; i < 5 + RTb.Rows.Count; i++)
{
tcHeader.Add(new TableHeaderCell());
tcHeader[i].Attributes.Add("colspan", "1");
tcHeader[i].Attributes.Add("style", "height:26px;font-size:10pt;color:White;background-color:#96A6BB; weight:80px;");
tcHeader[i].Text = RTb