我使用两个表第一个用于标题,另一个用于标识。从JavaScript我改变标题表每个列宽度与body表相同。每次在下拉列表中选择索引更改网格绑定操作执行。每次时间列宽度更改为我在JavaScript下面使用。
我在这里编写JavaScript代码:
jQuery(document).ready(function () {
var headergrid = $('#gridHeader').find("table")[0];
var bodygrid = $('#bodyHeader').find("table")[0];
var headerCellWidths = new Array();
for (var i = 0; i < bodygrid.getElementsByTagName('TH').length; i++) {
headerCellWidths[i] = bodygrid.getElementsByTagName('TH')[i].offsetWidth;
}
for (var i = 0; i < headerCellWidths.length; i++) {
headergrid.getElementsByTagName('TH')[i].style.width = parseInt(headerCellWidths[i]) + 'px';
}
});
ASP代码:
<div style="height: 34px; overflow: auto" id="gridHeader">
<table id="tbltemp" width="856px">
<tr id="temp">
<th>
TRANS ID
</th>
<th>
VC NO.
</th>
<th>
SUB NO.
</th>
<th>
DOMAIN
</th>
<th>
STATION
</th>
<th>
DTC
</th>
<th>
STATUS
</th>
<th>
REMARK
</th>
<th>
ENTERED DATETIME
</th>
<th>
</th>
</tr>
</table>
</div>
<div style="width: 859px; height: 450px; overflow: auto;" id="bodyHeader">
<asp:GridView ID="gvViewData" runat="server" AutoGenerateColumns="False" DataKeyNames="EC_TRANS_ID"
OnRowDataBound="gvViewRow_DataBound" OnDataBound="gvViewData_DataBound" OnRowCommand="gvViewData_RowCommand"
Visible="False" BackColor="White"
OnSelectedIndexChanging="gvViewData_SelectedIndexChanging"
>
<Columns>
<asp:BoundField DataField="EC_TRANS_ID" HeaderText="TRANS ID" ReadOnly="True">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="VC_NO" HeaderText="VC NO" ReadOnly="True">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="SUB_NO" HeaderText="SUB NO">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="RESERVED" HeaderText="Part No">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="DOMAIN_NAME" HeaderText="DOMAIN">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="STATION_ID" HeaderText="STATION">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="DTC_CODE" HeaderText="DTC">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="STATUS" HeaderText="STATUS">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="REMARK" HeaderText="REMARK">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="ENTERED_DATETIME" HeaderText="ENTERED DATETIME" >
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:ButtonField CommandName="Prameters" Text="Parameter">
<ItemStyle />
</asp:ButtonField>
</Columns>
</asp:GridView>
</div>
但问题是,如果将宽度设置为110px,则将其指定为105px或68px,则将其指定为72px。请给我一些建议。