Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Changing Values of a Webcontrol Embedded in the Header Row of a DataGrid


Message #1 by "Dean Santillan" <webmaster@5...> on Tue, 16 Jul 2002 21:40:57 +0900
How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Tue, 16 Jul 2002 09:37:27 -0400
> How can i change or dynamically add values to
> label controls embedded in ListItemType.Header Row of the datagrid
> without using OnItemDataBound or ItemCreated Events?

	How can I fire a click event without using OnClick?  C'mon, how many
events do you want?  If you can't use ItemCreated directly then you're going
to have to inherit from DataGrid and make a mechanism that does it for you.

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 8:41 AM
To: ASP+
Subject: [aspx] Changing Values of a Webcontrol Embedded in the Header
Row of a DataGrid


How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan

Message #3 by "Dean Santillan" <webmaster@5...> on Tue, 16 Jul 2002 23:24:47 +0900
Hi Chuck,

I understand this but i am having trouble trying to get my head around this.
so I will explain what i am trying to do.

I have a querystring similar to this

?Bubun=26&Peji=48&Kokugo=Jp

I need to change the Label Control text property that is embedded in the
ListItemType.Header of the datagrid
according to the Kokugo(Language) parameter of the querystring.

I need it to be done using a class file and an xml file.
At present I have this code using the ItemDatBound Event in the code behind.
To me this is not convenient. As I would have to write it
into every page that has this.

private void dgListPages_ItemDataBound(object sender, DataGridItemEventArgs
e){
if(e.Item.ItemType == ListItemType.Header){
String Kokugo = "";
if(Request.Params["Kokugo"] != null){
Kokugo = Request.Params["Kokugo"];
}else{
Kokugo = "En";}
if(Kokugo == "En"){
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "ID:";}
else{
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "??";
}}}

I have an xml that has the the appropriate values for each of the items in
the Listitemtype.header row. Similar to this.



<lblPageIDHeader Language="En" Css="" Value="ID:" ToolTip="Page
Identification Number." />
<lblPageIDHeader Language="Jp" Css="" Value="??" ToolTip="??????" />

where lblPageIDHeader is the id of the Label control

I aslo have a class file that loads in the this xml and filters the
xml file according to language parameter in the querystring. Then
it scans the page looking for the webcontrol id eg: lblPageIDHeader.
It then works out what kind of webcontrol it is eg: label, hyperlink,
datagrid.
once it has worked it out it then looks for the attribute value in the xml
to add
it to the text property of the particular label. This works fine for all
webcontrols
until i hit the list webcontrols and there templates. here is an example of
that file

public static void TranslateControl(UserControl MyUserControl, String
ControlName, String Language)
{
XmlDocument doc = new XmlDocument();
doc.Load(MyUserControl.MapPath("Xml/" + ControlName + ".xml"));
XmlNodeList nodes = doc.SelectNodes("Ascx/*[@Language='" + Language + "']");
foreach (XmlNode anode in nodes){
Control c = MyUserControl.FindControl(anode.Name);
if (c != null){
switch ( c.GetType().ToString()){
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes["Value"].Value;
lb.ToolTip = anode.Attributes["ToolTip"].Value;
break;

case "System.Web.UI.WebControls.HyperLink":
HyperLink hl  = (HyperLink) c;
hl.Text = anode.Attributes["Value"].Value;
hl.ToolTip = anode.Attributes["ToolTip"].Value;
hl.NavigateUrl = anode.Attributes["LinkURL"].Value;
break;
////////////////////////////////////////////
case "System.Web.UI.WebControls.DataGrid":
From here I need to find the Label Control in the header control
this where i am stuck. So at the moment i am using the ItemDataBound Event
to change these values, how can i initiate this event from the class file to
achieve this functionality.
}}}}



Any help or articles would be greatly appreciated.

Thanks
Dean


-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 10:37 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


> How can i change or dynamically add values to
> label controls embedded in ListItemType.Header Row of the datagrid
> without using OnItemDataBound or ItemCreated Events?

	How can I fire a click event without using OnClick?  C'mon, how many
events do you want?  If you can't use ItemCreated directly then you're going
to have to inherit from DataGrid and make a mechanism that does it for you.

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 8:41 AM
To: ASP+
Subject: [aspx] Changing Values of a Webcontrol Embedded in the Header
Row of a DataGrid


How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan



Message #4 by Feduke Cntr Charles R <FedukeCR@m...> on Tue, 16 Jul 2002 10:39:44 -0400
> At present I have this code using the ItemDatBound Event in the code
behind.
> To me this is not convenient. As I would have to write it
> into every page that has this.

	Ahhh!  This is why you inherit, so you do it once, and then anytime
you place your derived control on a page it does everything you need it to
without requiring you to recode the entire thing each time.  Just derive
your DataGrid from the base DataGrid, and put your own ItemDataBound
override in the class, and then inherit from your new DataGrid anywhere you
need to (thus replacing the old DataGrids).

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 10:25 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


Hi Chuck,

I understand this but i am having trouble trying to get my head around this.
so I will explain what i am trying to do.

I have a querystring similar to this

?Bubun=26&Peji=48&Kokugo=Jp

I need to change the Label Control text property that is embedded in the
ListItemType.Header of the datagrid
according to the Kokugo(Language) parameter of the querystring.

I need it to be done using a class file and an xml file.
At present I have this code using the ItemDatBound Event in the code behind.
To me this is not convenient. As I would have to write it
into every page that has this.

private void dgListPages_ItemDataBound(object sender, DataGridItemEventArgs
e){
if(e.Item.ItemType == ListItemType.Header){
String Kokugo = "";
if(Request.Params["Kokugo"] != null){
Kokugo = Request.Params["Kokugo"];
}else{
Kokugo = "En";}
if(Kokugo == "En"){
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "ID:";}
else{
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "??";
}}}

I have an xml that has the the appropriate values for each of the items in
the Listitemtype.header row. Similar to this.



<lblPageIDHeader Language="En" Css="" Value="ID:" ToolTip="Page
Identification Number." />
<lblPageIDHeader Language="Jp" Css="" Value="??" ToolTip="??????" />

where lblPageIDHeader is the id of the Label control

I aslo have a class file that loads in the this xml and filters the
xml file according to language parameter in the querystring. Then
it scans the page looking for the webcontrol id eg: lblPageIDHeader.
It then works out what kind of webcontrol it is eg: label, hyperlink,
datagrid.
once it has worked it out it then looks for the attribute value in the xml
to add
it to the text property of the particular label. This works fine for all
webcontrols
until i hit the list webcontrols and there templates. here is an example of
that file

public static void TranslateControl(UserControl MyUserControl, String
ControlName, String Language)
{
XmlDocument doc = new XmlDocument();
doc.Load(MyUserControl.MapPath("Xml/" + ControlName + ".xml"));
XmlNodeList nodes = doc.SelectNodes("Ascx/*[@Language='" + Language + "']");
foreach (XmlNode anode in nodes){
Control c = MyUserControl.FindControl(anode.Name);
if (c != null){
switch ( c.GetType().ToString()){
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes["Value"].Value;
lb.ToolTip = anode.Attributes["ToolTip"].Value;
break;

case "System.Web.UI.WebControls.HyperLink":
HyperLink hl  = (HyperLink) c;
hl.Text = anode.Attributes["Value"].Value;
hl.ToolTip = anode.Attributes["ToolTip"].Value;
hl.NavigateUrl = anode.Attributes["LinkURL"].Value;
break;
////////////////////////////////////////////
case "System.Web.UI.WebControls.DataGrid":
From here I need to find the Label Control in the header control
this where i am stuck. So at the moment i am using the ItemDataBound Event
to change these values, how can i initiate this event from the class file to
achieve this functionality.
}}}}



Any help or articles would be greatly appreciated.

Thanks
Dean


-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 10:37 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


> How can i change or dynamically add values to
> label controls embedded in ListItemType.Header Row of the datagrid
> without using OnItemDataBound or ItemCreated Events?

	How can I fire a click event without using OnClick?  C'mon, how many
events do you want?  If you can't use ItemCreated directly then you're going
to have to inherit from DataGrid and make a mechanism that does it for you.

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 8:41 AM
To: ASP+
Subject: [aspx] Changing Values of a Webcontrol Embedded in the Header
Row of a DataGrid


How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan




Message #5 by "Dean Santillan" <webmaster@5...> on Wed, 17 Jul 2002 00:10:06 +0900
inheritance how to do or would i need a book?
Are there any articles on inheritance that you know of off by hand.
Thanks for your advice Chuck!!

Dean

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 11:40 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


> At present I have this code using the ItemDatBound Event in the code
behind.
> To me this is not convenient. As I would have to write it
> into every page that has this.

	Ahhh!  This is why you inherit, so you do it once, and then anytime
you place your derived control on a page it does everything you need it to
without requiring you to recode the entire thing each time.  Just derive
your DataGrid from the base DataGrid, and put your own ItemDataBound
override in the class, and then inherit from your new DataGrid anywhere you
need to (thus replacing the old DataGrids).

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 10:25 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


Hi Chuck,

I understand this but i am having trouble trying to get my head around this.
so I will explain what i am trying to do.

I have a querystring similar to this

?Bubun=26&Peji=48&Kokugo=Jp

I need to change the Label Control text property that is embedded in the
ListItemType.Header of the datagrid
according to the Kokugo(Language) parameter of the querystring.

I need it to be done using a class file and an xml file.
At present I have this code using the ItemDatBound Event in the code behind.
To me this is not convenient. As I would have to write it
into every page that has this.

private void dgListPages_ItemDataBound(object sender, DataGridItemEventArgs
e){
if(e.Item.ItemType == ListItemType.Header){
String Kokugo = "";
if(Request.Params["Kokugo"] != null){
Kokugo = Request.Params["Kokugo"];
}else{
Kokugo = "En";}
if(Kokugo == "En"){
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "ID:";}
else{
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "??";
}}}

I have an xml that has the the appropriate values for each of the items in
the Listitemtype.header row. Similar to this.



<lblPageIDHeader Language="En" Css="" Value="ID:" ToolTip="Page
Identification Number." />
<lblPageIDHeader Language="Jp" Css="" Value="??" ToolTip="??????" />

where lblPageIDHeader is the id of the Label control

I aslo have a class file that loads in the this xml and filters the
xml file according to language parameter in the querystring. Then
it scans the page looking for the webcontrol id eg: lblPageIDHeader.
It then works out what kind of webcontrol it is eg: label, hyperlink,
datagrid.
once it has worked it out it then looks for the attribute value in the xml
to add
it to the text property of the particular label. This works fine for all
webcontrols
until i hit the list webcontrols and there templates. here is an example of
that file

public static void TranslateControl(UserControl MyUserControl, String
ControlName, String Language)
{
XmlDocument doc = new XmlDocument();
doc.Load(MyUserControl.MapPath("Xml/" + ControlName + ".xml"));
XmlNodeList nodes = doc.SelectNodes("Ascx/*[@Language='" + Language + "']");
foreach (XmlNode anode in nodes){
Control c = MyUserControl.FindControl(anode.Name);
if (c != null){
switch ( c.GetType().ToString()){
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes["Value"].Value;
lb.ToolTip = anode.Attributes["ToolTip"].Value;
break;

case "System.Web.UI.WebControls.HyperLink":
HyperLink hl  = (HyperLink) c;
hl.Text = anode.Attributes["Value"].Value;
hl.ToolTip = anode.Attributes["ToolTip"].Value;
hl.NavigateUrl = anode.Attributes["LinkURL"].Value;
break;
////////////////////////////////////////////
case "System.Web.UI.WebControls.DataGrid":
>From here I need to find the Label Control in the header control
this where i am stuck. So at the moment i am using the ItemDataBound Event
to change these values, how can i initiate this event from the class file to
achieve this functionality.
}}}}



Any help or articles would be greatly appreciated.

Thanks
Dean


-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 10:37 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


> How can i change or dynamically add values to
> label controls embedded in ListItemType.Header Row of the datagrid
> without using OnItemDataBound or ItemCreated Events?

	How can I fire a click event without using OnClick?  C'mon, how many
events do you want?  If you can't use ItemCreated directly then you're going
to have to inherit from DataGrid and make a mechanism that does it for you.

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 8:41 AM
To: ASP+
Subject: [aspx] Changing Values of a Webcontrol Embedded in the Header
Row of a DataGrid


How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan






Message #6 by Feduke Cntr Charles R <FedukeCR@m...> on Tue, 16 Jul 2002 11:42:18 -0400
Dean,

	There's alot of examples in MSDN or gotdotnet.com or any of the
other web sites.  You probably don't need a book, but if you decide you want
to learn all the ins and outs of inheritance, you might want to consider
"Object Oriented Programming Step by Step with Microsoft Visual Basic and
Microsoft C#", 2001 or 2002, MS Press.

	Basically you do something like...

namespace Dean.Web.UI.WebControls
{
	public class DataGrid : System.Web.UI.WebControls.DataGrid
	{
		public DataGrid() : base() { } // generic constructor

		public override ItemCreated(object sender, DataGridEventArgs
e)
		{
			// do your stuff
		}
	}
}


- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 11:10 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


inheritance how to do or would i need a book?
Are there any articles on inheritance that you know of off by hand.
Thanks for your advice Chuck!!

Dean

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 11:40 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


> At present I have this code using the ItemDatBound Event in the code
behind.
> To me this is not convenient. As I would have to write it
> into every page that has this.

	Ahhh!  This is why you inherit, so you do it once, and then anytime
you place your derived control on a page it does everything you need it to
without requiring you to recode the entire thing each time.  Just derive
your DataGrid from the base DataGrid, and put your own ItemDataBound
override in the class, and then inherit from your new DataGrid anywhere you
need to (thus replacing the old DataGrids).

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 10:25 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


Hi Chuck,

I understand this but i am having trouble trying to get my head around this.
so I will explain what i am trying to do.

I have a querystring similar to this

?Bubun=26&Peji=48&Kokugo=Jp

I need to change the Label Control text property that is embedded in the
ListItemType.Header of the datagrid
according to the Kokugo(Language) parameter of the querystring.

I need it to be done using a class file and an xml file.
At present I have this code using the ItemDatBound Event in the code behind.
To me this is not convenient. As I would have to write it
into every page that has this.

private void dgListPages_ItemDataBound(object sender, DataGridItemEventArgs
e){
if(e.Item.ItemType == ListItemType.Header){
String Kokugo = "";
if(Request.Params["Kokugo"] != null){
Kokugo = Request.Params["Kokugo"];
}else{
Kokugo = "En";}
if(Kokugo == "En"){
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "ID:";}
else{
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "??";
}}}

I have an xml that has the the appropriate values for each of the items in
the Listitemtype.header row. Similar to this.



<lblPageIDHeader Language="En" Css="" Value="ID:" ToolTip="Page
Identification Number." />
<lblPageIDHeader Language="Jp" Css="" Value="??" ToolTip="??????" />

where lblPageIDHeader is the id of the Label control

I aslo have a class file that loads in the this xml and filters the
xml file according to language parameter in the querystring. Then
it scans the page looking for the webcontrol id eg: lblPageIDHeader.
It then works out what kind of webcontrol it is eg: label, hyperlink,
datagrid.
once it has worked it out it then looks for the attribute value in the xml
to add
it to the text property of the particular label. This works fine for all
webcontrols
until i hit the list webcontrols and there templates. here is an example of
that file

public static void TranslateControl(UserControl MyUserControl, String
ControlName, String Language)
{
XmlDocument doc = new XmlDocument();
doc.Load(MyUserControl.MapPath("Xml/" + ControlName + ".xml"));
XmlNodeList nodes = doc.SelectNodes("Ascx/*[@Language='" + Language + "']");
foreach (XmlNode anode in nodes){
Control c = MyUserControl.FindControl(anode.Name);
if (c != null){
switch ( c.GetType().ToString()){
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes["Value"].Value;
lb.ToolTip = anode.Attributes["ToolTip"].Value;
break;

case "System.Web.UI.WebControls.HyperLink":
HyperLink hl  = (HyperLink) c;
hl.Text = anode.Attributes["Value"].Value;
hl.ToolTip = anode.Attributes["ToolTip"].Value;
hl.NavigateUrl = anode.Attributes["LinkURL"].Value;
break;
////////////////////////////////////////////
case "System.Web.UI.WebControls.DataGrid":
>From here I need to find the Label Control in the header control
this where i am stuck. So at the moment i am using the ItemDataBound Event
to change these values, how can i initiate this event from the class file to
achieve this functionality.
}}}}



Any help or articles would be greatly appreciated.

Thanks
Dean


-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 10:37 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


> How can i change or dynamically add values to
> label controls embedded in ListItemType.Header Row of the datagrid
> without using OnItemDataBound or ItemCreated Events?

	How can I fire a click event without using OnClick?  C'mon, how many
events do you want?  If you can't use ItemCreated directly then you're going
to have to inherit from DataGrid and make a mechanism that does it for you.

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 8:41 AM
To: ASP+
Subject: [aspx] Changing Values of a Webcontrol Embedded in the Header
Row of a DataGrid


How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan







Message #7 by "Dean Santillan" <webmaster@5...> on Thu, 18 Jul 2002 11:36:56 +0900
Thanks Heaps Chuck,
I finally worked it out. Now I can drop the grid onto any page
with out having to rewrite the code.

But I have a problem, when I drop the custom grid onto the page
it says error creating control.

Thanks Dean

public class EvolusysGrid : System.Web.UI.WebControls.DataGrid
	{
		public EvolusysGrid()
		{
			// Pageing Defaults
			this.PagerStyle.Mode = PagerMode.NumericPages;
			this.PagerStyle.BackColor = Color.FromName("#F7F7DE");
			this.PagerStyle.CssClass = "Text";
			this.PagerStyle.Position = PagerPosition.TopAndBottom;
			this.PagerStyle.VerticalAlign = VerticalAlign.Middle;
			this.PagerStyle.ForeColor = Color.Black;
			this.PagerStyle.HorizontalAlign = HorizontalAlign.Center;
			this.PagerStyle.PageButtonCount = 10;

			// Header Style Default DataGrid Settings
			this.HeaderStyle.BackColor = Color.FromName("#6B696B");
			this.HeaderStyle.CssClass = "Text";
			this.HeaderStyle.ForeColor = Color.White;
			this.HeaderStyle.HorizontalAlign = HorizontalAlign.Left;
			this.HeaderStyle.VerticalAlign = VerticalAlign.Middle;

			// FooterStyle Default DataGrid Settings
			this.FooterStyle.BackColor = Color.FromName("#CCCC99");
			this.FooterStyle.CssClass = "Text";
			this.FooterStyle.HorizontalAlign = HorizontalAlign.Left;
			this.FooterStyle.VerticalAlign = VerticalAlign.Middle;

			// Selected Item Styles Default DataGrid Setting
			this.SelectedItemStyle.BackColor = Color.FromName("#CE5D5A");
			this.SelectedItemStyle.CssClass = "Text";
			this.SelectedItemStyle.Font.Bold = true;
			this.SelectedItemStyle.ForeColor = Color.White;
			this.SelectedItemStyle.HorizontalAlign = HorizontalAlign.Left;
			this.SelectedItemStyle.VerticalAlign = VerticalAlign.Middle;

			// Alternating Item Styles Default DataGrid Settingd
			this.AlternatingItemStyle.BackColor = Color.White;
			this.AlternatingItemStyle.CssClass = "Text";
			this.AlternatingItemStyle.ForeColor = Color.Black;
			this.AlternatingItemStyle.HorizontalAlign = HorizontalAlign.Left;
			this.AlternatingItemStyle.VerticalAlign = VerticalAlign.Middle;

			// ItemStyle Default DataGrid Settings
			this.ItemStyle.ForeColor = Color.Black;
			this.ItemStyle.BackColor = Color.FromName("#F7F7DE");
			this.ItemStyle.CssClass = "Text";
			this.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
			this.ItemStyle.VerticalAlign = VerticalAlign.Middle;

			//Datagrids Default Visual Settings
			this.ID = "EvolusysGrid";
			this.GridLines = GridLines.Both;;
			this.Width = new Unit(90, UnitType.Percentage);
			this.ShowFooter = true;
			this.CellPadding = 4;
			this.CellSpacing = 0;
			this.HorizontalAlign = HorizontalAlign.Center;
			this.BorderWidth = 1;
			this.BorderStyle = BorderStyle.None;
			this.BorderColor = Color.FromName("#DEDFDE");
			this.ForeColor = Color.Black;
			this.BackColor = Color.White;
			this.AllowCustomPaging = false;
			this.AllowPaging = true;
			this.AllowSorting = true;
			this.PageSize = 10;
			this.AutoGenerateColumns = false;

			this.ItemCreated += new DataGridItemEventHandler(Evo_ItemCreated);

		}


		public void Evo_ItemCreated(Object sender, DataGridItemEventArgs e)
	{
		ListItemType NewItemType = e.Item.ItemType;


			if(NewItemType == ListItemType.Header)
			{

				String Kokugo = "";

				if(HttpContext.Current.Request.Params["Kokugo"] != null)
				{
					Kokugo = HttpContext.Current.Request.Params["Kokugo"];
				}
				else
				{
					Kokugo = "En";
				}

				//HttpContext.Current.Response.Write(Kokugo);
				HttpContext.Current.Trace.Write(Kokugo);

				XmlDocument NewXmlDoc = new XmlDocument();

NewXmlDoc.Load(HttpContext.Current.Server.MapPath("Controls/Pages/Xml/view.x
ml"));
				XmlNodeList nodes = NewXmlDoc.SelectNodes("Ascx/*[@Language='" + Kokugo
+ "']");
				TableCell NewTableCell = (TableCell)e.Item.Controls[0];

				HttpContext.Current.Trace.Write(NewTableCell.GetType().ToString());

				foreach (XmlNode anode in nodes)
				{
					HttpContext.Current.Trace.Write(anode.Name);

					for(int i = 0;i<NewTableCell.Controls.Count;i++)
					{
						Object o = NewTableCell.FindControl(anode.Name);
						if (o != null)
						{
							switch ( o.GetType().ToString())
							{
								case "System.Web.UI.WebControls.Label":
									Label lb = (Label) o;
									lb.Text = anode.Attributes["Value"].Value;
									lb.ToolTip = anode.Attributes["ToolTip"].Value;
									lb.CssClass = anode.Attributes["Css"].Value;
									break;
							}
						}
						else
						{
							HttpContext.Current.Trace.Write("Nothing Inhere na");
						}
					}


				}




			}

	}

	}

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 17, 2002 12:42 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


Dean,

	There's alot of examples in MSDN or gotdotnet.com or any of the
other web sites.  You probably don't need a book, but if you decide you want
to learn all the ins and outs of inheritance, you might want to consider
"Object Oriented Programming Step by Step with Microsoft Visual Basic and
Microsoft C#", 2001 or 2002, MS Press.

	Basically you do something like...

namespace Dean.Web.UI.WebControls
{
	public class DataGrid : System.Web.UI.WebControls.DataGrid
	{
		public DataGrid() : base() { } // generic constructor

		public override ItemCreated(object sender, DataGridEventArgs
e)
		{
			// do your stuff
		}
	}
}


- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 11:10 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


inheritance how to do or would i need a book?
Are there any articles on inheritance that you know of off by hand.
Thanks for your advice Chuck!!

Dean

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 11:40 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


> At present I have this code using the ItemDatBound Event in the code
behind.
> To me this is not convenient. As I would have to write it
> into every page that has this.

	Ahhh!  This is why you inherit, so you do it once, and then anytime
you place your derived control on a page it does everything you need it to
without requiring you to recode the entire thing each time.  Just derive
your DataGrid from the base DataGrid, and put your own ItemDataBound
override in the class, and then inherit from your new DataGrid anywhere you
need to (thus replacing the old DataGrids).

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 10:25 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


Hi Chuck,

I understand this but i am having trouble trying to get my head around this.
so I will explain what i am trying to do.

I have a querystring similar to this

?Bubun=26&Peji=48&Kokugo=Jp

I need to change the Label Control text property that is embedded in the
ListItemType.Header of the datagrid
according to the Kokugo(Language) parameter of the querystring.

I need it to be done using a class file and an xml file.
At present I have this code using the ItemDatBound Event in the code behind.
To me this is not convenient. As I would have to write it
into every page that has this.

private void dgListPages_ItemDataBound(object sender, DataGridItemEventArgs
e){
if(e.Item.ItemType == ListItemType.Header){
String Kokugo = "";
if(Request.Params["Kokugo"] != null){
Kokugo = Request.Params["Kokugo"];
}else{
Kokugo = "En";}
if(Kokugo == "En"){
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "ID:";}
else{
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "??";
}}}

I have an xml that has the the appropriate values for each of the items in
the Listitemtype.header row. Similar to this.



<lblPageIDHeader Language="En" Css="" Value="ID:" ToolTip="Page
Identification Number." />
<lblPageIDHeader Language="Jp" Css="" Value="??" ToolTip="??????" />

where lblPageIDHeader is the id of the Label control

I aslo have a class file that loads in the this xml and filters the
xml file according to language parameter in the querystring. Then
it scans the page looking for the webcontrol id eg: lblPageIDHeader.
It then works out what kind of webcontrol it is eg: label, hyperlink,
datagrid.
once it has worked it out it then looks for the attribute value in the xml
to add
it to the text property of the particular label. This works fine for all
webcontrols
until i hit the list webcontrols and there templates. here is an example of
that file

public static void TranslateControl(UserControl MyUserControl, String
ControlName, String Language)
{
XmlDocument doc = new XmlDocument();
doc.Load(MyUserControl.MapPath("Xml/" + ControlName + ".xml"));
XmlNodeList nodes = doc.SelectNodes("Ascx/*[@Language='" + Language + "']");
foreach (XmlNode anode in nodes){
Control c = MyUserControl.FindControl(anode.Name);
if (c != null){
switch ( c.GetType().ToString()){
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes["Value"].Value;
lb.ToolTip = anode.Attributes["ToolTip"].Value;
break;

case "System.Web.UI.WebControls.HyperLink":
HyperLink hl  = (HyperLink) c;
hl.Text = anode.Attributes["Value"].Value;
hl.ToolTip = anode.Attributes["ToolTip"].Value;
hl.NavigateUrl = anode.Attributes["LinkURL"].Value;
break;
////////////////////////////////////////////
case "System.Web.UI.WebControls.DataGrid":
>From here I need to find the Label Control in the header control
this where i am stuck. So at the moment i am using the ItemDataBound Event
to change these values, how can i initiate this event from the class file to
achieve this functionality.
}}}}



Any help or articles would be greatly appreciated.

Thanks
Dean


-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 10:37 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


> How can i change or dynamically add values to
> label controls embedded in ListItemType.Header Row of the datagrid
> without using OnItemDataBound or ItemCreated Events?

	How can I fire a click event without using OnClick?  C'mon, how many
events do you want?  If you can't use ItemCreated directly then you're going
to have to inherit from DataGrid and make a mechanism that does it for you.

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 8:41 AM
To: ASP+
Subject: [aspx] Changing Values of a Webcontrol Embedded in the Header
Row of a DataGrid


How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan









Message #8 by Feduke Cntr Charles R <FedukeCR@m...> on Thu, 18 Jul 2002 09:33:03 -0400
Dean,

	There is approximate one kazillion other things that you need to do
in order for you to not get this error from the HTML Designer.  I have to be
honest with you - I hate the HTML Designer more than anything else in
computers (except for, perhaps, anything Oracle) - and I haven't looked too
deeply into making any of my in-house controls compatible with it.  In fact
you can turn HTML Designer off entirely in the options if you [choose the
right path and] want disable it.

	There's a bunch of attributes that determine how the properties
should be displayed, and there's an interface or another control that you
need to develop that determines what HTML to render at design time and a
bunch of other things.  Anyone else care to elaborate?

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Wednesday, July 17, 2002 10:37 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


Thanks Heaps Chuck,
I finally worked it out. Now I can drop the grid onto any page
with out having to rewrite the code.

But I have a problem, when I drop the custom grid onto the page
it says error creating control.

Thanks Dean

public class EvolusysGrid : System.Web.UI.WebControls.DataGrid
	{
		public EvolusysGrid()
		{
			// Pageing Defaults
			this.PagerStyle.Mode = PagerMode.NumericPages;
			this.PagerStyle.BackColor 
Color.FromName("#F7F7DE");
			this.PagerStyle.CssClass = "Text";
			this.PagerStyle.Position 
PagerPosition.TopAndBottom;
			this.PagerStyle.VerticalAlign 
VerticalAlign.Middle;
			this.PagerStyle.ForeColor = Color.Black;
			this.PagerStyle.HorizontalAlign 
HorizontalAlign.Center;
			this.PagerStyle.PageButtonCount = 10;

			// Header Style Default DataGrid Settings
			this.HeaderStyle.BackColor 
Color.FromName("#6B696B");
			this.HeaderStyle.CssClass = "Text";
			this.HeaderStyle.ForeColor = Color.White;
			this.HeaderStyle.HorizontalAlign 
HorizontalAlign.Left;
			this.HeaderStyle.VerticalAlign 
VerticalAlign.Middle;

			// FooterStyle Default DataGrid Settings
			this.FooterStyle.BackColor 
Color.FromName("#CCCC99");
			this.FooterStyle.CssClass = "Text";
			this.FooterStyle.HorizontalAlign 
HorizontalAlign.Left;
			this.FooterStyle.VerticalAlign 
VerticalAlign.Middle;

			// Selected Item Styles Default DataGrid Setting
			this.SelectedItemStyle.BackColor 
Color.FromName("#CE5D5A");
			this.SelectedItemStyle.CssClass = "Text";
			this.SelectedItemStyle.Font.Bold = true;
			this.SelectedItemStyle.ForeColor = Color.White;
			this.SelectedItemStyle.HorizontalAlign 
HorizontalAlign.Left;
			this.SelectedItemStyle.VerticalAlign 
VerticalAlign.Middle;

			// Alternating Item Styles Default DataGrid Settingd
			this.AlternatingItemStyle.BackColor = Color.White;
			this.AlternatingItemStyle.CssClass = "Text";
			this.AlternatingItemStyle.ForeColor = Color.Black;
			this.AlternatingItemStyle.HorizontalAlign 
HorizontalAlign.Left;
			this.AlternatingItemStyle.VerticalAlign 
VerticalAlign.Middle;

			// ItemStyle Default DataGrid Settings
			this.ItemStyle.ForeColor = Color.Black;
			this.ItemStyle.BackColor 
Color.FromName("#F7F7DE");
			this.ItemStyle.CssClass = "Text";
			this.ItemStyle.HorizontalAlign 
HorizontalAlign.Left;
			this.ItemStyle.VerticalAlign = VerticalAlign.Middle;

			//Datagrids Default Visual Settings
			this.ID = "EvolusysGrid";
			this.GridLines = GridLines.Both;;
			this.Width = new Unit(90, UnitType.Percentage);
			this.ShowFooter = true;
			this.CellPadding = 4;
			this.CellSpacing = 0;
			this.HorizontalAlign = HorizontalAlign.Center;
			this.BorderWidth = 1;
			this.BorderStyle = BorderStyle.None;
			this.BorderColor = Color.FromName("#DEDFDE");
			this.ForeColor = Color.Black;
			this.BackColor = Color.White;
			this.AllowCustomPaging = false;
			this.AllowPaging = true;
			this.AllowSorting = true;
			this.PageSize = 10;
			this.AutoGenerateColumns = false;

			this.ItemCreated += new
DataGridItemEventHandler(Evo_ItemCreated);

		}


		public void Evo_ItemCreated(Object sender,
DataGridItemEventArgs e)
	{
		ListItemType NewItemType = e.Item.ItemType;


			if(NewItemType == ListItemType.Header)
			{

				String Kokugo = "";

	
if(HttpContext.Current.Request.Params["Kokugo"] != null)
				{
					Kokugo 
HttpContext.Current.Request.Params["Kokugo"];
				}
				else
				{
					Kokugo = "En";
				}

	
//HttpContext.Current.Response.Write(Kokugo);
				HttpContext.Current.Trace.Write(Kokugo);

				XmlDocument NewXmlDoc = new XmlDocument();

NewXmlDoc.Load(HttpContext.Current.Server.MapPath("Controls/Pages/Xml/view.x
ml"));
				XmlNodeList nodes 
NewXmlDoc.SelectNodes("Ascx/*[@Language='" + Kokugo
+ "']");
				TableCell NewTableCell 
(TableCell)e.Item.Controls[0];

	
HttpContext.Current.Trace.Write(NewTableCell.GetType().ToString());

				foreach (XmlNode anode in nodes)
				{
	
HttpContext.Current.Trace.Write(anode.Name);

					for(int i 
0;i<NewTableCell.Controls.Count;i++)
					{
						Object o 
NewTableCell.FindControl(anode.Name);
						if (o != null)
						{
							switch (
o.GetType().ToString())
							{
								case
"System.Web.UI.WebControls.Label":
	
Label lb = (Label) o;
	
lb.Text = anode.Attributes["Value"].Value;
	
lb.ToolTip = anode.Attributes["ToolTip"].Value;
	
lb.CssClass = anode.Attributes["Css"].Value;
	
break;
							}
						}
						else
						{
	
HttpContext.Current.Trace.Write("Nothing Inhere na");
						}
					}


				}




			}

	}

	}

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 17, 2002 12:42 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


Dean,

	There's alot of examples in MSDN or gotdotnet.com or any of the
other web sites.  You probably don't need a book, but if you decide you want
to learn all the ins and outs of inheritance, you might want to consider
"Object Oriented Programming Step by Step with Microsoft Visual Basic and
Microsoft C#", 2001 or 2002, MS Press.

	Basically you do something like...

namespace Dean.Web.UI.WebControls
{
	public class DataGrid : System.Web.UI.WebControls.DataGrid
	{
		public DataGrid() : base() { } // generic constructor

		public override ItemCreated(object sender, DataGridEventArgs
e)
		{
			// do your stuff
		}
	}
}


- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 11:10 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


inheritance how to do or would i need a book?
Are there any articles on inheritance that you know of off by hand.
Thanks for your advice Chuck!!

Dean

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 11:40 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the He
ader Row of a DataGrid


> At present I have this code using the ItemDatBound Event in the code
behind.
> To me this is not convenient. As I would have to write it
> into every page that has this.

	Ahhh!  This is why you inherit, so you do it once, and then anytime
you place your derived control on a page it does everything you need it to
without requiring you to recode the entire thing each time.  Just derive
your DataGrid from the base DataGrid, and put your own ItemDataBound
override in the class, and then inherit from your new DataGrid anywhere you
need to (thus replacing the old DataGrids).

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 10:25 AM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


Hi Chuck,

I understand this but i am having trouble trying to get my head around this.
so I will explain what i am trying to do.

I have a querystring similar to this

?Bubun=26&Peji=48&Kokugo=Jp

I need to change the Label Control text property that is embedded in the
ListItemType.Header of the datagrid
according to the Kokugo(Language) parameter of the querystring.

I need it to be done using a class file and an xml file.
At present I have this code using the ItemDatBound Event in the code behind.
To me this is not convenient. As I would have to write it
into every page that has this.

private void dgListPages_ItemDataBound(object sender, DataGridItemEventArgs
e){
if(e.Item.ItemType == ListItemType.Header){
String Kokugo = "";
if(Request.Params["Kokugo"] != null){
Kokugo = Request.Params["Kokugo"];
}else{
Kokugo = "En";}
if(Kokugo == "En"){
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "ID:";}
else{
Label d = new Label();
d = (Label)e.Item.FindControl("lblPageIDHeader");
d.Text = "??";
}}}

I have an xml that has the the appropriate values for each of the items in
the Listitemtype.header row. Similar to this.



<lblPageIDHeader Language="En" Css="" Value="ID:" ToolTip="Page
Identification Number." />
<lblPageIDHeader Language="Jp" Css="" Value="??" ToolTip="??????" />

where lblPageIDHeader is the id of the Label control

I aslo have a class file that loads in the this xml and filters the
xml file according to language parameter in the querystring. Then
it scans the page looking for the webcontrol id eg: lblPageIDHeader.
It then works out what kind of webcontrol it is eg: label, hyperlink,
datagrid.
once it has worked it out it then looks for the attribute value in the xml
to add
it to the text property of the particular label. This works fine for all
webcontrols
until i hit the list webcontrols and there templates. here is an example of
that file

public static void TranslateControl(UserControl MyUserControl, String
ControlName, String Language)
{
XmlDocument doc = new XmlDocument();
doc.Load(MyUserControl.MapPath("Xml/" + ControlName + ".xml"));
XmlNodeList nodes = doc.SelectNodes("Ascx/*[@Language='" + Language + "']");
foreach (XmlNode anode in nodes){
Control c = MyUserControl.FindControl(anode.Name);
if (c != null){
switch ( c.GetType().ToString()){
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes["Value"].Value;
lb.ToolTip = anode.Attributes["ToolTip"].Value;
break;

case "System.Web.UI.WebControls.HyperLink":
HyperLink hl  = (HyperLink) c;
hl.Text = anode.Attributes["Value"].Value;
hl.ToolTip = anode.Attributes["ToolTip"].Value;
hl.NavigateUrl = anode.Attributes["LinkURL"].Value;
break;
////////////////////////////////////////////
case "System.Web.UI.WebControls.DataGrid":
>From here I need to find the Label Control in the header control
this where i am stuck. So at the moment i am using the ItemDataBound Event
to change these values, how can i initiate this event from the class file to
achieve this functionality.
}}}}



Any help or articles would be greatly appreciated.

Thanks
Dean


-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Tuesday, July 16, 2002 10:37 PM
To: ASP+
Subject: [aspx] RE: Changing Values of a Webcontrol Embedded in the
Header Row of a DataGrid


> How can i change or dynamically add values to
> label controls embedded in ListItemType.Header Row of the datagrid
> without using OnItemDataBound or ItemCreated Events?

	How can I fire a click event without using OnClick?  C'mon, how many
events do you want?  If you can't use ItemCreated directly then you're going
to have to inherit from DataGrid and make a mechanism that does it for you.

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, July 16, 2002 8:41 AM
To: ASP+
Subject: [aspx] Changing Values of a Webcontrol Embedded in the Header
Row of a DataGrid


How can i change or dynamically add values to
label controls embedded in ListItemType.Header Row of the datagrid
without using OnItemDataBound or ItemCreated Events?

Thanks
Dean Santillan











  Return to Index