如何设置列标题文本?

时间:2011-11-28 20:31:34

标签: asp.net vb.net gridview

我想设置列的文本。 GridView的正确语法是什么?

Me.gvRefBetweenLineOfBiz.DataSource = query
Me.gvRefBetweenLineOfBiz.DataBind()
EnableControlVisibility(True)

1 个答案:

答案 0 :(得分:2)

您可能希望禁用自动生成列,并为要在GridView中显示的每列创建BoundField。每个BoundField都有HeaderText属性,用于控制列的标题文本。

来自文档:

<asp:gridview id="CustomersGridView" 
    datasourceid="CustomersSqlDataSource" 
    autogeneratecolumns="false"
    autogenerateeditbutton="true"
    allowpaging="true" 
    datakeynames="CustomerID"  
    runat="server">

    <columns>
      <asp:boundfield datafield="CustomerID"
        readonly="true"      
        headertext="Customer ID"/>
      <asp:boundfield datafield="CompanyName"
        convertemptystringtonull="true"
        headertext="Customer Name"/>
      <asp:boundfield datafield="Address"
        convertemptystringtonull="true"
        headertext="Address"/>
      <asp:boundfield datafield="City"
        convertemptystringtonull="true"
        headertext="City"/>
      <asp:boundfield datafield="PostalCode"
        convertemptystringtonull="true"
        headertext="ZIP Code"/>
      <asp:boundfield datafield="Country"
        convertemptystringtonull="true"
        headertext="Country"/>
    </columns>

  </asp:gridview>