473,513 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherited Datagrid Destroys Datasource?????

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
1 1197
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4316
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
1
4282
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
0
693
by: Richard Ryerson | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls (watch...
1
2352
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.