Unable to set column header via code

A

AndrewGomes

I am trying to change the header of a column on the datagrid. I
reference the column using the syntax myGrid.Columns(0).HeaderText.
The problem is that the change is not reflected on the grid. Any
ideas?

I have attached an example:

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

Private cn as SqlConnection = New
SqlConnection("Server=someserver;user id=sa;password=;Initial
Catalog=MyDB")

Sub Page_Load(Sender as Object, E as EventArgs)
If Not Page.IsPostBack Then
BindLanguages()
End If

' This does not work!!!! Why?
LanguagesMaint.Columns(0).HeaderText = "New header!!!"
End Sub

Sub BindLanguages()
Dim adapter as SqlDataAdapter = New SqlDataAdapter("Select
LanguageID, Name From Language", cn)

Dim myDataSet as DataSet = new DataSet
adapter.Fill(myDataSet, "languages")

LanguagesMaint.DataSource =
myDataSet.Tables("languages").DefaultView
LanguagesMaint.DataBind()
End Sub

</script>
<html>
<head>
</head>
<body>
<form id="form1" name="form1" runat="server">
<p>
<asp:DataGrid id="LanguagesMaint" runat="server"
DataKeyField="LanguageID" AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField="Name"
HeaderText="##Header##">
<HeaderStyle width="200px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top