隐藏gridview列标题

时间:2014-07-03 14:50:40

标签: asp.net vb.net gridview

我有一个gridview,它是从一个带有ajax的sqldatasource填充的,它是从radcombox下拉列表中触发的。以下不起作用,因为从技术上讲,gridview没有加载。有一个简单的工作吗?

Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged
    GridView1.HeaderRow.Cells(1).Visible = False
End Sub

3 个答案:

答案 0 :(得分:12)

<asp:GridView ID="GridView1" runat="server" ShowHeader="False">
        </asp:GridView>
aspx页面上的

showheader = false

答案 1 :(得分:4)

只需在DataBound事件中绑定整个GridView后隐藏单元格:

Protected Sub GridView1_DataBound(sender As Object, e As EventArgs)  
    GridView1.HeaderRow.Cells(1).Visible = False
End Sub

<asp:GridView ID="GridView1" runat="server" OnDataBound="GridView1_DataBound">

只知道这只隐藏了标题单元格的内容,而不是整个列。

答案 2 :(得分:0)

在数据绑定方法后或在页面加载方法上绑定网格后编写代码行

   GridView1.DataBind();
   if (GridView1.Rows.Count > 0)// check if grid not empty
      {
            GridView1.HeaderRow.Cells[1].Visible = false;//hide grid column header
            GridView1.Columns[1].Visible = false;//hide grid column value
      }