RE: [DOTNET] BoundColumn Problöem

Fritz Onion <[email protected]> Mon, 17 Jun 2002 13:14:23 -0400
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <001e01c21622$6e50bf80$6301a8c0@Patroklus>
Unfortunately, you want this server-side code to be evaluated just prior
to data binding. <%= %> will be evaluated after data binding, at which
point is apparently too late to change the header values of the columns.
<%# %> will be evaluated during data binding, and as you discovered, can
not even be used within a column element.
The only solution I see is to set the header text yourself
programmatically, just prior to binding the grid, like:

Private void Page_Load(object sender, EventArgs e)
{
    //...
    DataGrid1.Columns[0].HeaderText = GetHeader("TITLES");
    DataGrid1.DataSource = db.GetAllData();
    DataGrid1.DataBind();
    //...
}

        -Fritz

PS - I'm ccing the DotNetWeb list. If you have further comments on this
thread, please post them there.

Fritz Onion
DevelopMentor
http://staff.develop.com/onion/

> -----Original Message-----
> From: The DOTNET list will be retired 7/1/02
> [mailto:[email protected]] On Behalf Of Rahul Sharma
> Sent: Monday, June 17, 2002 11:13 AM
> To: [email protected]
> Subject: [DOTNET] BoundColumn Problöem
> 
> Hi,
> 
> I have this ASPX file:
> //DataGrid.aspx
> 
> <%@ Page language="c#" Codebehind="DataGrid.aspx.cs"
> AutoEventWireup="false" Inherits="DataControls.DataGrid" %>
> <HTML>
>         <HEAD>
>                 <title>DataGrid</title>
>                 <meta name="GENERATOR" Content="Microsoft Visual
Studio
> 7.0">
>                 <meta name="CODE_LANGUAGE" Content="C#">
>                 <meta name="vs_defaultClientScript"
content="JavaScript">
>                 <meta name="vs_targetSchema" content="
> http://schemas.microsoft.com/intellisense/ie5">
>         </HEAD>
>         <body MS_POSITIONING="GridLayout">
>                 <form id="DataGrid" method="post" runat="server">
>                 <asp:DataGrid id="DataGrid1"
AutoGenerateColumns="False"
> style="Z-INDEX: 101; LEFT: 30px; POSITION: absolute; TOP: 21px"
> runat="server" BorderColor="Tan"       BorderWidth="1px"
> BackColor="LightGoldenrodYellow" CellPadding="2" GridLines="None"
> ForeColor="Black">
>                                 <SelectedItemStyle
ForeColor="GhostWhite"
> BackColor="DarkSlateBlue"></SelectedItemStyle>
>                                 <AlternatingItemStyle
> BackColor="PaleGoldenrod"></AlternatingItemStyle>
>                                 <HeaderStyle Font-Bold="True"
> BackColor="Tan"></HeaderStyle>
>                                 <FooterStyle
> BackColor="Tan"></FooterStyle>
>                                 <PagerStyle HorizontalAlign="Center"
> ForeColor="DarkSlateBlue" BackColor="PaleGoldenrod"></PagerStyle>
>                                 <Columns>
>                                         <asp:BoundColumn
DataField="Title"
> HeaderText='<%= GetHeader("TILES") %>'>
>                                         </asp:BoundColumn>
>                                 </Columns>
>                         </asp:DataGrid>
>                 </form>
>         </body>
> </HTML>
> 
> 
> and CODE-BEHIND:
> //DataGrid.aspx.cs
> 
> namespace DataControls
> {
>         /// <summary>
>         /// Summary description for DataGrid.
>         /// </summary>
>         public class DataGrid : System.Web.UI.Page
>         {
>                 protected System.Web.UI.WebControls.DataGrid
DataGrid1;
> 
>                 private void Page_Load(object sender, System.EventArgs
e)
>                 {
>                         // DB is a Database wrapper to execute Stored
> Procedures
>                         DB db = new DB();
>                         // Setting the DataSource as GetAllData() is
> returning a DataSet
>                         DataGrid1.DataSource = db.GetAllData();
>                         DataGrid1.DataBind();
>                 }
> 
>                 public string GetHeader(String Text){
>                         return Text;
>                 }
> 
>                 #region Web Form Designer generated code
>                         //Automated Code
>                 #endregion
>         }
> }
> 
> 
> Now problem starts when I try to set the Header Text of BoundColumn in
> ASPX file like this:
> 
> <asp:BoundColumn DataField="Title" HeaderText= '<%=
GetHeader("TITLES")
> %>' >  </asp:BoundColumn>
> 
> OR
> 
> <asp:BoundColumn DataField="Title" HeaderText= '<%
GetHeader("TITLES") ;
> %>' >  </asp:BoundColumn>
> 
> I get nothing as Header Text But no error reported, and when I try to
set
> it as DataBound Value like this:
> 
> <asp:BoundColumn DataField="Title" HeaderText= '<%#
GetHeader("TITLES")
> %>' >  </asp:BoundColumn>
> 
> I get error back that BoundColumn doesn't support DataBinding.
> 
> 
> 
> I don't understand how to do this, I could do it on runtime only in
the
> code behind file but couldn't get any way to do it in ASPX file.
> 
> 
> 
> Any Pointers....
> 
> 
> 
> Thanks.
> 
> 
> 
> Rahul.
> 
> 
> 
> 
> 
> 
> 
> You can read messages from the DOTNET archive, unsubscribe from
DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.