By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,627 Members | 1,781 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,627 IT Pros & Developers. It's quick & easy.

Inherited Datagrid Destroys Datasource?????

P: n/a
I 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.getElementByI d('{0}').createCap
tion()\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:wcSDBGrid 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).
*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Turgeson wrote:
I 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.

Do not use tabs in posted code, use 2 or 4 spaces for indents,
manually wrap code at about 70~75 characters.

Since this is a JavaScript forum, it's preferred that only JavaScript
code is posted here. If your script is generated by some other script
or program, post only the generated JavaScript code (i.e. what the
client will see).

Otherwise you are coming to a JavaScript forum to fix server
scripting issues (ASP/PHP/Pearl/Python/whatever) that are likely
better fixed in a forum dedicated to their use.

[...] sbScript.Append("<script>\n");
<script type="text/javascript">
if(_sCaption.Length > 0)
{
// include a caption
sbScript.AppendFormat("sCap=document.getElementByI d('{0}').createCap
tion()\n" +
"sCap.innerHTML = '{1}';\n", this.ID, _sCaption);
}


This appears to be trying to get a reference to an element using
getElementById, then replace the content using innerHTML. It also
appears that the element it refers to is not written to the document
until further down the page.

If that is so, then likely the element does not exist when you go
looking for it, so run your script after the element is created.

You have two options - run your script using body onload, or place it
just after the script (HTML or other) that creates the element.

[...]

--
Zif
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.