|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article describes another Using the codeThis is a customer control. I include the source code for the control and a test project how to use it. As any customer control, you need to add the reference to the project. On the ASPX page: (...)
< MOD:MODataGrid> id="DataGrid1" style="Z-INDEX: 101;
LEFT: 320px; POSITION: absolute; TOP: 136px"
runat="server">
On the aspx.cs file add: protected MouseOverDataGrid.MODataGrid DataGrid1;
I used the Datagrid tutorial example from http://asp.net for the test project The ControlA simple Inherit from [assembly:TagPrefix("MouseOverDataGrid", "MOD")]
namespace MouseOverDataGrid
{
/// <summary>
/// Summary description for MouseOverDataGrid.
/// </summary>
public class MODataGrid : System.Web.UI.WebControls.DataGrid
{
[Category("Design"), Description("OverLink Color")]
private string sBackgroundColor = "#dddddd";
public string SpecialLinkColor
{
get{return(sBackgroundColor);}
set{sBackgroundColor=value;}
}
[Category("Design"), Description("OverLink Hand Type")]
private bool bOverLinkHand = false;
public bool OverLinkHand
{
get{return(bOverLinkHand);}
set{bOverLinkHand=value;}
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
string sDataGridID = this.ID.ToString();
string sCursor = "";
if ( OverLinkHand == true )
sCursor = "elm.style.cursor = Cursor;\r";
string sJavaScript = "< script language="'\""javascript\"'>\r" +
"function ShowRow1(elm, BgColour, FgColour)\r" +
"{\r" +
"elm.bgColor = BgColour;\r" + sCursor +
"}\r" +
"function HilightRow(elm, hover, highlight)\r" +
"{\r" +
" var BgColour = (hover)? \"" + SpecialLinkColor + "\" : \"white\";\r" +
" var FgColour = \"black\";\r" +
" var Cursor = (hover)? \"hand\" : \"auto\";\r" +
" ShowRow1(elm, BgColour, FgColour);\r" +
" return false;\r" +
"}\r" +
"function RowOn() { return HilightRow(this, true, false); }\r" +
"function RowOff() { return HilightRow(this, false, false); }\r" +
"function RowClick()\r" +
"{\r" +
" HilightRow(this, false, true);\r" +
" var elm = eval('document.getElementById(\"' + this.name + '_link\")');\r" +
" if (elm) elm.click();\r" +
" return true;\r" +
"}\r" +
"var table = document.getElementById(\"" + sDataGridID + "\");\r" +
"var rows = table.getElementsByTagName(\"tr\");\r" +
"for (var i = 0; i < rows.length; i++) {\r" +
"rows[i].onmouseover = RowOn;\r" +
"rows[i].onmouseout = RowOff;\r" +
//"rows[i].onclick = RowClick;" +
"}\r</script>\r";
base.Render (writer);
base.Page.Response.Write(sJavaScript);
}
}
Points of InterestFor the Datagrid to work you have to make sure you do not add any color on the item background. If you are using paging, add same color in the footer.
|
||||||||||||||||||||||