Inherited Datagrid Destroys Datasource?????

Discussion in 'ASP .Net Web Controls' started by Turgeson, Apr 1, 2005.

  1. Turgeson

    Turgeson Guest

    thought this would be relatively simple but apparently it is not. I'm
    trying to create a Custom Server Control class that will automatically
    build a grid that conforms with a style consistent in my application. I
    have no problems referencing the class in my pages. I can even step
    through and check my property values Everything works fine until the
    Render method is called. Then all derived properties are nulled.


    // Control Class

    using System;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.IO;

    namespace customcontrols
    {
    /// <summary>
    /// Summary description for XGrid.
    /// </summary>
    [toolboxdata("<{0}:xgrid runat=server></{0}:XGrid>")]
    public class XGrid : System.Web.UI.WebControls.DataGrid
    {
    private string _sCaption = "";
    private bool _bBuildScript = false;
    private bool _bBandGrid = true;
    private StringBuilder sbScript = new StringBuilder();

    public string Caption
    {
    get
    {
    return _sCaption;
    }
    set
    {
    _sCaption = value;
    _bBuildScript = true;
    }
    }

    public bool BandGrid
    {
    get
    {
    return _bBandGrid;
    }
    set
    {
    _bBandGrid = value;
    _bBuildScript = true;
    }
    }

    private void BuildScript()
    {
    sbscript.append("<script>\n");
    if(_sCaption.Length > 0)
    {
    // include a caption

    sbScript.AppendFormat("sCap=document.getElementById('{0}').createCaption()\n"
    +
    "sCap.innerHTML = '{1}';\n", this.ID,
    _sCaption);
    }
    if(_bBandGrid)
    {
    // band table
    sbScript.AppendFormat("setTableBands('{0}');\n", this.ID);
    }
    sbscript.append("</script>");
    }

    /// <summary>
    /// Render this control to the output parameter specified.
    /// </summary>
    /// <param name="output"> The HTML writer to write out to </param>
    protected override void Render(HtmlTextWriter output)
    {
    base.Render(output);
    if(_bBuildScript)
    {
    BuildScript();
    base.Page.Response.Write(sbScript.ToString());
    }

    }
    }
    }

    // Aspx
    <%@ Page language="c#" Codebehind="frmCourseDetails.aspx.cs"
    AutoEventWireup="false"
    Inherits="sdb.student_information.frmCourseDetails" %>
    <%@ Register TagPrefix="sdb" Namespace="sdb.usercontrols"
    Assembly="sdb"%>
    <html>
    <body>
    <form id=Form1 method=post runat="server">
    <sdb:XGrid id=dgDetails style="LEFT: -1px; POSITION: absolute; TOP:
    -1px" runat="server" Width="477px" AutoGenerateColumns="False"
    ShowHeader="False" CellPadding="2" BorderWidth="0" BandGrid=true>
    <Columns>
    <asp:BoundColumn DataField="ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="Internal"></asp:BoundColumn>
    <asp:BoundColumn
    DataField="Description"></asp:BoundColumn>
    <asp:BoundColumn DataField="Max"
    ItemStyle-HorizontalAlign=Center></asp:BoundColumn>
    <asp:BoundColumn DataField="P/F"
    ItemStyle-HorizontalAlign=Center></asp:BoundColumn>
    <asp:BoundColumn DataField="Weight"
    ItemStyle-HorizontalAlign=Right></asp:BoundColumn>
    <asp:BoundColumn DataField="Order"
    ItemStyle-HorizontalAlign=Center></asp:BoundColumn>
    </Columns>
    </sdb:wcSDBGrid>
    </FORM>
    </body>
    </HTML>

    Any ideas?? I've tried everything I can think of. The control will write
    the javascript, but it acts like an empty Dataset (which it is not).
     
    Turgeson, Apr 1, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    542
    Brendan Reynolds
    Jun 30, 2005
  2. Stefan Kuhr
    Replies:
    2
    Views:
    605
    Stefan Kuhr
    Nov 21, 2006
  3. Replies:
    2
    Views:
    780
  4. Turgeson

    Inherited Datagrid Destroys Datasource?????

    Turgeson, Apr 1, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    136
    Turgeson
    Apr 1, 2005
  5. 7stud --
    Replies:
    11
    Views:
    426
    7stud --
    Nov 9, 2007
Loading...

Share This Page