Changing the column name in GridView using HTML or C#

前端 未结 2 1849
离开以前
离开以前 2021-01-21 03:57

The point is I have used GridView in my project. And I have assigned the Values to GridView using the SQLConn, SQlDataAdapter

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 04:12

    You can change the column name by ordinal position - although this is not a robust way if the columns get reordered:

    grd.HeaderRow.Cells(iCount).Text = "my column name"
    

    There is a (liitle known? little used?)property of the header cells called AccessibleHeaderText

    
         
             
         
    
    

    Its designated for page automation so:

    For iCount = 0 To grd.HeaderRow.Cells.Count - 1
         Dim oCol As DataControlField = grd.Columns(iCount)
         If String.Compare(oCol.AccessibleHeaderText, "MY_FIXED_KEY_VALUE", True) = 0 Then
               grd.HeaderRow.Cells(iCount).Text = "my column name"
               Exit For
         End If
    Next
    

    Will be quite robust.

    Of course you can use case or whatever for cycling though the columns

    HTH

提交回复
热议问题