Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Create a scrollable DataGrid custom Component

Reply
Thread Tools

Create a scrollable DataGrid custom Component

 
 
Guillermo Castro
Guest
Posts: n/a
 
      12-29-2003
Hi,

I want to create a custom Datagrid component that derives from the
default DataGrid and adds a <div> tag with the 'overflow' style. I've
added two properties to my custom datagrid, ScrollWidth and
ScrollHeight, to be set on the div. However, when I try to set the
properties on the designer, I get a "Invalid property value" error.

Has anyone done something similar, or can someone point me to a good
example on how to subclass DataGrid to get this kind of behavior?

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Robert McLaws
Guest
Posts: n/a
 
      01-06-2004
Guillermo,

Unfortunately, this is nowhere near as easy as it looks. It took me over a
year of experimentation on and off to get it right. Instead of spending 5+
hours trying to figure it out, I would suggest that you check out
http://www.scrollingdatagrid.com instead. For $10, you can have a simple
control that allows the header and footer to stay stationary, while the data
area scrolls. For $40 you can get the source code and see how it all is
done.

Feel free to e-mail me if you have any questions, and let me know if I can
help you in any way.

Sincerely,
Robert W. McLaws
President and Chief Software Architect
Microsoft ASP.NET MVP
Interscape Technologies, Inc.
Simple. Affordable. Solutions.T
http://www.interscapeusa.com
http://www.codesideassistance.com
http://www.genxdotnet.com
http://www.scrollingdatagrid.com
http://www.longhornblogs.com
http://www.patchdayreview.com

"Guillermo Castro" <> wrote in message
news:...
> Hi,
>
> I want to create a custom Datagrid component that derives from the
> default DataGrid and adds a <div> tag with the 'overflow' style. I've
> added two properties to my custom datagrid, ScrollWidth and
> ScrollHeight, to be set on the div. However, when I try to set the
> properties on the designer, I get a "Invalid property value" error.
>
> Has anyone done something similar, or can someone point me to a good
> example on how to subclass DataGrid to get this kind of behavior?
>
> Thanks.
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
 
Walter Gomero
Guest
Posts: n/a
 
      01-06-2004

Guillermo here's the code:
create a file scroll.htc and add this:

// JavaScript Document
<PUBLIC:ATTACH event="ondocumentready" handler="onDocumentReady" />
<SCRIPT language="JScript">
function onDocumentReady()
{
// Create elements
var tblHeader = this.cloneNode(false);
var tblBody = this.cloneNode(false);
var divCntr = document.createElement("DIV");

// Get column widths
var rgWidths = new Array();
for (var i = 0; i < this.rows[0].cells.length; i++)
{
rgWidths[i] = this.rows[0].cells[i].offsetWidth;
}

// Add header row
var tbdyHeader = document.createElement("TBODY");
tblHeader.appendChild(tbdyHeader);
tbdyHeader.appendChild(this.rows[0].cloneNode(true));

// Add body rows
var tbdyBody = document.createElement("TBODY");
tblBody.appendChild(tbdyBody);

for (var i = 1; i < this.rows.length; i++)
{
var oRow = this.rows[i].cloneNode(true);
tbdyBody.appendChild(oRow);
}

// Set up body container
divCntr.style.overflow = "auto";
if (this.bodyHeight) divCntr.style.height = this.bodyHeight;
divCntr.appendChild(tblBody);

// Change existing table
for (var i = this.rows.length; i > 0; i--)
{
this.rows[i-1].removeNode(true);
}
var tr1 = this.insertRow();
var td1 = tr1.insertCell();
var tr2 = this.insertRow();
var td2 = tr2.insertCell();

td1.appendChild(tblHeader);
td2.appendChild(divCntr);

// Set column widths of all but the last column
for (var i = 0; i < rgWidths.length - 1; i++)
{
tblHeader.rows[0].cells[i].width = rgWidths[i];
tblBody.rows[0].cells[i].width = rgWidths[i];
}

tblHeader.style.fontSize = "100%";
tblHeader.width = "100%";
tblHeader.style.tableLayout = "fixed";
tblHeader.className = this.headerCSS ? this.headerCSS : "";
tblHeader.border = 0;

tblBody.style.fontSize = "100%";
tblBody.width = "100%";
tblBody.style.tableLayout = "fixed";
tblBody.className = this.bodyCSS ? this.bodyCSS : "";

tblBody.border = 0;

this.cellSpacing = 0;
this.cellPadding = 0;
}
</SCRIPT>

then add the following to you css:

tblMain
{
behavior:url(scroll.htc);
background-color: highlight;
border: 1px solid darkblue;
font-family: Verdana;
font-size: .8em;
}
tblHeader
{
color: highlighttext;
}
tblBody
{
background-color: #EEEEEE;
color: darkblue;
}

finally add (bodyCSS, headerCSS, cssClass and bodyHeight) to your
datagrid:

<asp:datagrid
id="mainGrid"
runat="server"
bodyCSS="tblBody"
headerCSS="tblHeader"
cssclass="tblMain"
bodyHeight="600px"
width="100%"
CellPadding="2"
CellSpacing="2"
GridLines="none"
Font-Size="9"
HeaderStyle-Font-Bold="true"
AllowSorting="true"
OnSortCommand="SortCommand"
autogeneratecolumns="false"
AllowPaging="true"
OnPreRender="DataGrid1_PreRender"
OnItemCreated="ItemCreated"
onPageIndexChanged="setPage"
ShowFooter="true" ShowHeader="true"
HeaderStyle-HorizontalAlign="Center">


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Walter Gomero
Guest
Posts: n/a
 
      01-06-2004
create a file scroll.htc and add the following:
// JavaScript Document
<PUBLIC:ATTACH event="ondocumentready" handler="onDocumentReady" />
<SCRIPT language="JScript">
function onDocumentReady()
{
// Create elements
var tblHeader = this.cloneNode(false);
var tblBody = this.cloneNode(false);
var divCntr = document.createElement("DIV");

// Get column widths
var rgWidths = new Array();
for (var i = 0; i < this.rows[0].cells.length; i++)
{
rgWidths[i] = this.rows[0].cells[i].offsetWidth;
}

// Add header row
var tbdyHeader = document.createElement("TBODY");
tblHeader.appendChild(tbdyHeader);
tbdyHeader.appendChild(this.rows[0].cloneNode(true));

// Add body rows
var tbdyBody = document.createElement("TBODY");
tblBody.appendChild(tbdyBody);

for (var i = 1; i < this.rows.length; i++)
{
var oRow = this.rows[i].cloneNode(true);
tbdyBody.appendChild(oRow);
}

// Set up body container
divCntr.style.overflow = "auto";
if (this.bodyHeight) divCntr.style.height = this.bodyHeight;
divCntr.appendChild(tblBody);

// Change existing table
for (var i = this.rows.length; i > 0; i--)
{
this.rows[i-1].removeNode(true);
}
var tr1 = this.insertRow();
var td1 = tr1.insertCell();
var tr2 = this.insertRow();
var td2 = tr2.insertCell();

td1.appendChild(tblHeader);
td2.appendChild(divCntr);

// Set column widths of all but the last column
for (var i = 0; i < rgWidths.length - 1; i++)
{
tblHeader.rows[0].cells[i].width = rgWidths[i];
tblBody.rows[0].cells[i].width = rgWidths[i];
}

tblHeader.style.fontSize = "100%";
tblHeader.width = "100%";
tblHeader.style.tableLayout = "fixed";
tblHeader.className = this.headerCSS ? this.headerCSS : "";
tblHeader.border = 0;

tblBody.style.fontSize = "100%";
tblBody.width = "100%";
tblBody.style.tableLayout = "fixed";
tblBody.className = this.bodyCSS ? this.bodyCSS : "";

tblBody.border = 0;

this.cellSpacing = 0;
this.cellPadding = 0;
}
</SCRIPT>

add the following lines to you css style:

.tblMain
{
behavior:url(scroll.htc);
background-color: highlight;
border: 1px solid darkblue;
font-family: Verdana;
font-size: .8em;
}
.tblHeader
{
color: highlighttext;
}
.tblBody
{
background-color: #EEEEEE;
color: darkblue;
}

finally add the following to your datagrid:
bodyCSS="tblBody"
headerCSS="tblHeader"
cssclass="tblMain"
bodyHeight="600px"

<asp:datagrid
id="mainGrid"
runat="server"
bodyCSS="tblBody"
headerCSS="tblHeader"
cssclass="tblMain"
bodyHeight="600px"
width="100%"
CellPadding="2"
CellSpacing="2"
GridLines="none"
Font-Size="9"
HeaderStyle-Font-Bold="true"
AllowSorting="true"
OnSortCommand="SortCommand"
autogeneratecolumns="false"
AllowPaging="true"
OnPreRender="DataGrid1_PreRender"
OnItemCreated="ItemCreated"
onPageIndexChanged="setPage"
ShowFooter="true" ShowHeader="true"
HeaderStyle-HorizontalAlign="Center">

regards,

walter gomero

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to create scrollable editor window using curses Andy Elvey Python 0 09-27-2009 08:50 AM
Create a scrollable DIV in webpage? Noozer HTML 3 05-15-2005 09:58 PM
How can I create a separately scrollable area? JezB ASP .Net 3 07-02-2004 06:31 PM
Scrollable Datagrid... EMW ASP .Net 5 06-05-2004 05:24 PM
Scrollable datagrid makthar ASP .Net 1 07-16-2003 04:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57