我有一个带有自动生成列的gridview,我以编程方式设置了我想格式化列宽。这是我在后面的代码中为我的 gridview 编写的代码...
If Not Page.IsPostBack Then
Dim budgetTable As New DataTable("Budgets")
budgetTable.Columns.Add("Approval Date", GetType(Date))
budgetTable.Columns.Add("Total Amount", GetType(String))
budgetTable.Columns.Add("Comments", GetType(String))
budgetTable.Columns.Add("Initials", GetType(String))
Try
For i As Integer = 0 To 0
Dim tableRow As DataRow = budgetTable.NewRow()
tableRow("Approval Date") = Date.Today
tableRow("Total Amount") = ""
tableRow("Comments") = ""
tableRow("Initials") = ""
budgetTable.Rows.Add (tableRow)
Next
Session("BudgetsTable") = budgetTable
BindData()
Catch ex As Exception
End Try
End If
这是html端的gridview:
<asp:GridView ID="gvOLIAdj" runat="server" CssClass="td8" CellPadding="4" ForeColor="#333333" PageSize="2" ViewStateMode="Enabled">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField EditText="Add" ShowEditButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>