Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
AndrewGomes #1
Unable to set column header via code
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>
AndrewGomes Guest
-
Header in a template column
Hi, I have a checkbox in the header of a template column in a datagrid. How can I check during runtime that whether checkbox is checked or not?I... -
Column Header
I have a web form with a datagrid. The datagrid has 5 columns. In design mode each column has header text. I defined the header text, data source,... -
Custom tool warning: DiscoCodeGenerator unable to initialize code generator. No code generated.
I created a brand new WebService (HelloWorld) and when I attempt to add this WebService to a WindowsForm project I get the following error message in... -
Image in header column (not replacing column header text)
I have a sortable (asc/desc) datagrid and would like to add a small arrow icon (down/up) next to the column header text to improve the UI. Is this... -
DataGrid Column Header
Hi All, The column header is getting an underline once the sort is enabled on that particular column. I want to have it in such a way that the... -
Sonali.NET[MVP] #2
Re: Unable to set column header via code
Take a look @
[url]http://www.c-sharpcorner.com/Code/2003/June/DataGridHeaderText.asp[/url]
"AndrewGomes" <andrewgomes@hotmail.com> wrote in message
news:c9f9937d.0307170431.5836c73f@posting.google.c om...> 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>
Sonali.NET[MVP] Guest
-
AndrewGomes #3
Re: Unable to set column header via code
BRILLIANT!!! That worked. Thanks for the quick response!
"Sonali.NET[MVP]" <xb_sonalix@hotmail.com> wrote in message news:<uGLxBDHTDHA.2252@TK2MSFTNGP12.phx.gbl>...> Take a look @
> [url]http://www.c-sharpcorner.com/Code/2003/June/DataGridHeaderText.asp[/url]
>AndrewGomes Guest



Reply With Quote

