Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: DataList - Embedded Controls


Message #1 by "Dean Santillan" <webmaster@5...> on Tue, 21 May 2002 12:35:27
Hi,

I am interested to know how I can manipulate the properties of web form 
controls embedded
in the header template of the datalist.

I have a datalist that has label controls in the header template that i 
would like to change the text of according to the querystring. I am able 
to access all the web from controls on the page but not in the datalist 
control.

I really have no idea where i should begin or what to look for. I played 
with it all i can see is to get a the datalistitem and then work my 
through that. But how is where i stop.

Any ideas or articles on this topic would be appreciated.

This how i am working through the controls 
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;                           
							break;
					
	case "System.Web.UI.WebControls.LinkButton":
							LinkButton lk = 
(LinkButton) c;
							lk.Text = 
anode.Attributes["Value"].InnerText;
							break;
					
	case "System.Web.UI.WebControls.HyperLink":
							HyperLink hl  = 
(HyperLink) c;
							hl.Text = 
anode.Attributes["Value"].InnerText;
							break;
					
	case "System.Web.UI.WebControls.Button":
							Button NewBut  = 
(Button) c;
							NewBut.Text = 
anode.Attributes["Value"].InnerText;
							break;
					
	case "System.Web.UI.WebControls.DataList":
							DataList 
NewDataList = (DataList)c;
							break;
					
	case "System.Web.UI.WebControls.DropDownList":
							DropDownList ddl  
= (DropDownList) c;
                            			foreach (XmlNode itemNode 
in anode.ChildNodes) 
							{
								ListItem 
li = new ListItem();
                                			li.Text = itemNode
["text"][Language].InnerText;
								li.Value = 
itemNode["value"].InnerText;
                                			ddl.Items.Add(li);
							}
							break;
					}
				}
			}
This is my xml file

<Ascx>
	<!-- -->
	<ControlTitle Language="En" Css="" Value="View Site Sections" 
ToolTip="" />
	<ControlTitle Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢" 
ToolTip="" />
	<!-- -->
	<InstrText Language="En" Css="" Value="Select from the links int 
the list below to edit or add a section to the site." ToolTip="" />
	<InstrText Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢" 
ToolTip="" />
	<!-- -->
	<NewPage Language="En" Css="" Value="Add New Site Section" 
ToolTip="" />
	<NewPage Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢" 
ToolTip="" />
	<!-- -->
	<LbID Language="En" Css="" Value="ID:" ToolTip="" />
	<LbID Language="Ja" Css="" Value="?C?a" ToolTip="" />
	<!-- -->
	<Section Language="En" Css="" Value="Name:" ToolTip="" />
	<Section Language="Ja" Css="" Value="?¼?O" ToolTip="" />
	<!-- -->
	<Edit Language="En" Css="" Value="Edited:" ToolTip="" />
	<Edit Language="Ja" Css="" Value="Edited:" ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢" 
ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢" 
ToolTip="" />
</Ascx>

Thanks
Dean Santillan
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Tue, 21 May 2002 09:24:26 -0400
Dean,

	The easiest way to do this is create a control that inherits from a
DataList and override the ItemCreated event, calling the base class for
everything but the header.

namespace DeanSantillan.Web.UI.WebControls
{
   public class DeanGrid
   {
      public override void ItemCreated(Object sender, DataListItemEventArgs
e)
      {
         if (e.Item.ItemType == ListItemType.Header)
         {
            // do stuff here like adding additional controls
		TableCell cell = e.Item.Cells[0]; // first cell
		Literal label = new Literal("This is text!");
		cell.Controls.Add(label);
         }
         else
         {
            base.ItemCreated(sender, e);
         }
      }
   }
}

	You can go that route, or create your own ItemCreated(object,
DataListItemEventArgs) delegate void and += it to the OnItemCreated method
(or <... OnItemCreated="Your_Delegate" ...>).  I recommend inheriting if
you're going to use this class in many places.

HTH,
- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, May 21, 2002 8:35 AM
To: ASP+
Subject: [aspx] DataList - Embedded Controls


Hi,

I am interested to know how I can manipulate the properties of web form 
controls embedded
in the header template of the datalist.

I have a datalist that has label controls in the header template that i 
would like to change the text of according to the querystring. I am able 
to access all the web from controls on the page but not in the datalist 
control.

I really have no idea where i should begin or what to look for. I played 
with it all i can see is to get a the datalistitem and then work my 
through that. But how is where i stop.

Any ideas or articles on this topic would be appreciated.

This how i am working through the controls 
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;                           
							break;
					
	case "System.Web.UI.WebControls.LinkButton":
							LinkButton lk = 
(LinkButton) c;
							lk.Text = 
anode.Attributes["Value"].InnerText;
							break;
					
	case "System.Web.UI.WebControls.HyperLink":
							HyperLink hl  = 
(HyperLink) c;
							hl.Text = 
anode.Attributes["Value"].InnerText;
							break;
					
	case "System.Web.UI.WebControls.Button":
							Button NewBut  = 
(Button) c;
							NewBut.Text = 
anode.Attributes["Value"].InnerText;
							break;
					
	case "System.Web.UI.WebControls.DataList":
							DataList 
NewDataList = (DataList)c;
							break;
					
	case "System.Web.UI.WebControls.DropDownList":
							DropDownList ddl  
= (DropDownList) c;
                            			foreach (XmlNode itemNode 
in anode.ChildNodes) 
							{
								ListItem 
li = new ListItem();
                                			li.Text = itemNode
["text"][Language].InnerText;
								li.Value = 
itemNode["value"].InnerText;
                                			ddl.Items.Add(li);
							}
							break;
					}
				}
			}
This is my xml file

<Ascx>
	<!-- -->
	<ControlTitle Language="En" Css="" Value="View Site Sections" 
ToolTip="" />
	<ControlTitle Language="Ja" Css=""
Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c" 
ToolTip="" />
	<!-- -->
	<InstrText Language="En" Css="" Value="Select from the links int 
the list below to edit or add a section to the site." ToolTip="" />
	<InstrText Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c" 
ToolTip="" />
	<!-- -->
	<NewPage Language="En" Css="" Value="Add New Site Section" 
ToolTip="" />
	<NewPage Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c" 
ToolTip="" />
	<!-- -->
	<LbID Language="En" Css="" Value="ID:" ToolTip="" />
	<LbID Language="Ja" Css="" Value="fCfa" ToolTip="" />
	<!-- -->
	<Section Language="En" Css="" Value="Name:" ToolTip="" />
	<Section Language="Ja" Css="" Value="-1/4'O" ToolTip="" />
	<!-- -->
	<Edit Language="En" Css="" Value="Edited:" ToolTip="" />
	<Edit Language="Ja" Css="" Value="Edited:" ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c" 
ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c" 
ToolTip="" />
</Ascx>

Thanks
Dean Santillan
Message #3 by "Dean Santillan" <webmaster@5...> on Wed, 22 May 2002 16:13:41 +0900
Thanks Chuck,

but i am not that far deep into programming and do not know what you are on
about
I just cant see what that would do to help me.

All I want to do is access the datalistitem. If I can do that I am sure i
can do it simply
bbut i guess what you are saying will work but how to do I have no idea.

Thanks
Dean

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, May 21, 2002 12:35 PM
To: ASP+
Subject: [aspx] DataList - Embedded Controls


Hi,

I am interested to know how I can manipulate the properties of web form
controls embedded
in the header template of the datalist.

I have a datalist that has label controls in the header template that i
would like to change the text of according to the querystring. I am able
to access all the web from controls on the page but not in the datalist
control.

I really have no idea where i should begin or what to look for. I played
with it all i can see is to get a the datalistitem and then work my
through that. But how is where i stop.

Any ideas or articles on this topic would be appreciated.

This how i am working through the controls
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;
							break;

	case "System.Web.UI.WebControls.LinkButton":
							LinkButton lk 
(LinkButton) c;
							lk.Text 
anode.Attributes["Value"].InnerText;
							break;

	case "System.Web.UI.WebControls.HyperLink":
							HyperLink hl  
(HyperLink) c;
							hl.Text 
anode.Attributes["Value"].InnerText;
							break;

	case "System.Web.UI.WebControls.Button":
							Button NewBut  
(Button) c;
							NewBut.Text 
anode.Attributes["Value"].InnerText;
							break;

	case "System.Web.UI.WebControls.DataList":
							DataList
NewDataList = (DataList)c;
							break;

	case "System.Web.UI.WebControls.DropDownList":
							DropDownList ddl
= (DropDownList) c;
                            			foreach (XmlNode itemNode
in anode.ChildNodes)
							{
								ListItem
li = new ListItem();
                                			li.Text = itemNode
["text"][Language].InnerText;
								li.Value 
itemNode["value"].InnerText;
                                			ddl.Items.Add(li);
							}
							break;
					}
				}
			}
This is my xml file

<Ascx>
	<!-- -->
	<ControlTitle Language="En" Css="" Value="View Site Sections"
ToolTip="" />
	<ControlTitle Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢"
ToolTip="" />
	<!-- -->
	<InstrText Language="En" Css="" Value="Select from the links int
the list below to edit or add a section to the site." ToolTip="" />
	<InstrText Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢"
ToolTip="" />
	<!-- -->
	<NewPage Language="En" Css="" Value="Add New Site Section"
ToolTip="" />
	<NewPage Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢"
ToolTip="" />
	<!-- -->
	<LbID Language="En" Css="" Value="ID:" ToolTip="" />
	<LbID Language="Ja" Css="" Value="?C?a" ToolTip="" />
	<!-- -->
	<Section Language="En" Css="" Value="Name:" ToolTip="" />
	<Section Language="Ja" Css="" Value="?¼?O" ToolTip="" />
	<!-- -->
	<Edit Language="En" Css="" Value="Edited:" ToolTip="" />
	<Edit Language="Ja" Css="" Value="Edited:" ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢"
ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="?±?±?Å?ú?{?ê?ð?ü?ê?Ä?º?³?¢"
ToolTip="" />
</Ascx>

Thanks
Dean Santillan

Message #4 by Feduke Cntr Charles R <FedukeCR@m...> on Wed, 22 May 2002 08:49:37 -0400
Dean,

	From what I'm understanding, you have controls in the Header section
of the DataList control that you want to muck around with.  You said that
you cannot access the controls to change thier attributes.  I think your
only options are to either make a delegate that is added to the event chain
for ItemCreated, or inherit from DataList and override the ItemCreated event
(inheriting and overriding is a better solution if you have to this in
multiple places throughout your project).

- Chuck

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Wednesday, May 22, 2002 3:14 AM
To: ASP+
Subject: [aspx] RE: DataList - Embedded Controls


Thanks Chuck,

but i am not that far deep into programming and do not know what you are on
about
I just cant see what that would do to help me.

All I want to do is access the datalistitem. If I can do that I am sure i
can do it simply
bbut i guess what you are saying will work but how to do I have no idea.

Thanks
Dean

-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Tuesday, May 21, 2002 12:35 PM
To: ASP+
Subject: [aspx] DataList - Embedded Controls


Hi,

I am interested to know how I can manipulate the properties of web form
controls embedded
in the header template of the datalist.

I have a datalist that has label controls in the header template that i
would like to change the text of according to the querystring. I am able
to access all the web from controls on the page but not in the datalist
control.

I really have no idea where i should begin or what to look for. I played
with it all i can see is to get a the datalistitem and then work my
through that. But how is where i stop.

Any ideas or articles on this topic would be appreciated.

This how i am working through the controls
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;
							break;

	case "System.Web.UI.WebControls.LinkButton":
							LinkButton lk 
(LinkButton) c;
							lk.Text 
anode.Attributes["Value"].InnerText;
							break;

	case "System.Web.UI.WebControls.HyperLink":
							HyperLink hl  
(HyperLink) c;
							hl.Text 
anode.Attributes["Value"].InnerText;
							break;

	case "System.Web.UI.WebControls.Button":
							Button NewBut  
(Button) c;
							NewBut.Text 
anode.Attributes["Value"].InnerText;
							break;

	case "System.Web.UI.WebControls.DataList":
							DataList
NewDataList = (DataList)c;
							break;

	case "System.Web.UI.WebControls.DropDownList":
							DropDownList ddl
= (DropDownList) c;
                            			foreach (XmlNode itemNode
in anode.ChildNodes)
							{
								ListItem
li = new ListItem();
                                			li.Text = itemNode
["text"][Language].InnerText;
								li.Value 
itemNode["value"].InnerText;
                                			ddl.Items.Add(li);
							}
							break;
					}
				}
			}
This is my xml file

<Ascx>
	<!-- -->
	<ControlTitle Language="En" Css="" Value="View Site Sections"
ToolTip="" />
	<ControlTitle Language="Ja" Css=""
Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c"
ToolTip="" />
	<!-- -->
	<InstrText Language="En" Css="" Value="Select from the links int
the list below to edit or add a section to the site." ToolTip="" />
	<InstrText Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c"
ToolTip="" />
	<!-- -->
	<NewPage Language="En" Css="" Value="Add New Site Section"
ToolTip="" />
	<NewPage Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c"
ToolTip="" />
	<!-- -->
	<LbID Language="En" Css="" Value="ID:" ToolTip="" />
	<LbID Language="Ja" Css="" Value="fCfa" ToolTip="" />
	<!-- -->
	<Section Language="En" Css="" Value="Name:" ToolTip="" />
	<Section Language="Ja" Css="" Value="-1/4'O" ToolTip="" />
	<!-- -->
	<Edit Language="En" Css="" Value="Edited:" ToolTip="" />
	<Edit Language="Ja" Css="" Value="Edited:" ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c"
ToolTip="" />
	<!-- -->
	<TEMP Language="En" Css="" Value="TEMP" ToolTip="" />
	<TEMP Language="Ja" Css="" Value="'?'?'A"u-{OEe'?"u'e'A?o'3'c"
ToolTip="" />
</Ascx>

Thanks
Dean Santillan



  Return to Index