Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DataListItem in DataList does not render attributes/Tooltips

Reply
Thread Tools

DataListItem in DataList does not render attributes/Tooltips

 
 
Brian Paul
Guest
Posts: n/a
 
      01-15-2004
I've added a datalist (DataList1) to my web form. In code behind, i'm trying to render the "title" and "style" attribute on each DataListItem. But there appears to be a bug in the DataListItem because it ignores any attributes assigned to it.

running on win2003 server, .Net Framework 1.1

-------------- example ---------------------------------------------

DataList1.RepeatLayout = RepeatLayout.Table; // the datalistitem should be renderd as a tablecell

//loop that assigns titles to each cell:
for ....
DataList1.Items[idx].ToolTip = "xxxxxxxxxxxxxxxxxxxxxxxxx";

or

DataList1.Items[idx].AddAttribute("title","xxxxxxx");

or

DataList1.Items[idx].Style.Add("border-bottom", "solid 2px #3EFF3E");
....

in all cases, when the table cell is rendered, no "title" or "style" attribute is renderd.

Any Comments?

 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-17-2004

Hi Brian,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
I have reproduced out your problem, I will do some research on this issue,
I will reply to you ASAP.
Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-17-2004

Hi Brian,

Thanks for your waiting and your patience.
I have done a lot of research on your issue, and I found that this problem
is an already known issue.
I will help you to figure out a workaround for this.

============
Based on my understanding, you want to add style setting and attribute to
your DataListItem. I suppose your DataListItem will render as <tr> html tag
of html table.(If in your DataList ItemTemplate logic, you use table as
template)

So I think you should refer to the client script and css to get this done.
You can try the following Solution to see if it helps resolve your issue:

First, add "runat=server id="body"" to html body tag to make body tag as a
HtmlGenericControl control.
In codebehind, you can refer to body tag as server control as:
protected System.Web.UI.HtmlControls.HtmlGenericControl body;

In Buton click event:
private void Button1_Click(object sender, System.EventArgs e)
{
StringBuilder sb=new StringBuilder();
sb.Append("<style>");
sb.Append(".CssStyle1");
sb.Append("{");
sb.Append("font: 12pt verdana; ");
sb.Append("font-weight:700;");
sb.Append("colorrange;");
sb.Append("}");
sb.Append("</style>");

Page.RegisterClientScriptBlock("style",sb.ToString ());

foreach(DataListItem dlt in ItemsList.Items)
{
dlt.CssClass="CssStyle1";
}

StringBuilder sb_script=new StringBuilder();
sb_script.Append("<script language=\"javascript\">");
sb_script.Append("function addtitle()");
sb_script.Append("{");
sb_script.Append("var i;");
sb_script.Append("for(i=0;i<document.all(\"ItemsLi st\").rows.length;i++)");
sb_script.Append("{");
sb_script.Append("document.all(\"ItemsList\").rows[i].title=i+\"row\";");
sb_script.Append("}");
sb_script.Append("}");
sb_script.Append("</script>");

Page.RegisterClientScriptBlock("script",sb_script. ToString());

body.Attributes.Add("onload","addtitle()");
}

Code's explanation:
1).The code will dynamic generate css style class:
<style>
..CssStyle1
{
font: 12pt verdana;
font-weight:700;
colorrange;
}
</style>
2). Set the DataListItem's CssClass as this css class.
3). The code dynamic generate client javascript code to change the <tr>'s
title attribute, it will generate code like this:
function addtitle()
{
var i;
for(i=0;i<document.all("ItemsList").rows.length;i+ +)
{
document.all("ItemsList").rows[i].title=i+"row";
}
}
</script>
4). body.Attributes.Add("onload","addtitle()") add the addtile() to the
body tag's onload event.

===================
Please apply my suggestion above and let me know if it helps resolve your
problem.(Actualy, it works well on my side)

Thank you for your cooperation. If you have any questions or concerns,
please feel free to post it in the group. I will try my best to help you.
Hope you have a good experience in Microsoft Newsgroup.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Brian Paul
Guest
Posts: n/a
 
      01-21-2004
thanks Jeffrey,

actually, i'm trying to update the style attribue on the "td" generated from
the datalist. but your example applies to both. I currently use the
CssClass attribute on the control today to appy formatting. It's just that
i would like a little more granular control (some borders, others not) and
would like to use *both* the "style" tag in addition to the CssClass
attribute.

I assume this is a bug? Either way, thanks for your time on this and the
nice example/explanation.

Brian



""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Hi Brian,
>
> Thanks for your waiting and your patience.
> I have done a lot of research on your issue, and I found that this problem
> is an already known issue.
> I will help you to figure out a workaround for this.
>
> ============
> Based on my understanding, you want to add style setting and attribute to
> your DataListItem. I suppose your DataListItem will render as <tr> html

tag
> of html table.(If in your DataList ItemTemplate logic, you use table as
> template)
>
> So I think you should refer to the client script and css to get this done.
> You can try the following Solution to see if it helps resolve your issue:
>
> First, add "runat=server id="body"" to html body tag to make body tag as a
> HtmlGenericControl control.
> In codebehind, you can refer to body tag as server control as:
> protected System.Web.UI.HtmlControls.HtmlGenericControl body;
>
> In Buton click event:
> private void Button1_Click(object sender, System.EventArgs e)
> {
> StringBuilder sb=new StringBuilder();
> sb.Append("<style>");
> sb.Append(".CssStyle1");
> sb.Append("{");
> sb.Append("font: 12pt verdana; ");
> sb.Append("font-weight:700;");
> sb.Append("colorrange;");
> sb.Append("}");
> sb.Append("</style>");
>
> Page.RegisterClientScriptBlock("style",sb.ToString ());
>
> foreach(DataListItem dlt in ItemsList.Items)
> {
> dlt.CssClass="CssStyle1";
> }
>
> StringBuilder sb_script=new StringBuilder();
> sb_script.Append("<script language=\"javascript\">");
> sb_script.Append("function addtitle()");
> sb_script.Append("{");
> sb_script.Append("var i;");
>

sb_script.Append("for(i=0;i<document.all(\"ItemsLi st\").rows.length;i++)");
> sb_script.Append("{");
> sb_script.Append("document.all(\"ItemsList\").rows[i].title=i+\"row\";");
> sb_script.Append("}");
> sb_script.Append("}");
> sb_script.Append("</script>");
>
> Page.RegisterClientScriptBlock("script",sb_script. ToString());
>
> body.Attributes.Add("onload","addtitle()");
> }
>
> Code's explanation:
> 1).The code will dynamic generate css style class:
> <style>
> CssStyle1
> {
> font: 12pt verdana;
> font-weight:700;
> colorrange;
> }
> </style>
> 2). Set the DataListItem's CssClass as this css class.
> 3). The code dynamic generate client javascript code to change the <tr>'s
> title attribute, it will generate code like this:
> function addtitle()
> {
> var i;
> for(i=0;i<document.all("ItemsList").rows.length;i+ +)
> {
> document.all("ItemsList").rows[i].title=i+"row";
> }
> }
> </script>
> 4). body.Attributes.Add("onload","addtitle()") add the addtile() to the
> body tag's onload event.
>
> ===================
> Please apply my suggestion above and let me know if it helps resolve your
> problem.(Actualy, it works well on my side)
>
> Thank you for your cooperation. If you have any questions or concerns,
> please feel free to post it in the group. I will try my best to help you.
> Hope you have a good experience in Microsoft Newsgroup.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-23-2004

Hi Brian,

Thanks very much for your feedback.
I am glad my reply makes sense to you.

================================================== ========
Yes, I have confirmed that this datalist issue is bug of DataList control.
So I have tried to find out a workaround for you.

In my workaround in my reply, I apply the Css class on <tr> html
tag(Related with DataListItem object). Based on your feedback, I think you
want to apply it on <td> tag, to get this done, you should refer to
DataListItem.Controls collection, which all maps to the <td> tags.
So you can do like this:
foreach(DataListItem dlt in ItemsList.Items)
{
foreach(Control c in dlt.Controls)
{
WebControl wc=(WebControl)c;
wc.CssClass="CssStyle1";
}
}

The style attribute is encapsulate in the WebControl's Attribute
collection, because of this DataList bug, we can not make the Attribute
property take effect, so the only workaround I can think of is using Css
class. Maybe in next version, .Net will fix this bug and you can get this
done through Attribute.Add() method. But now, I think we have to work
around like this.

Thanks for your understanding.

================================================== ==============
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Julience
Guest
Posts: n/a
 
      03-02-2004
In the same way of thinking, I cannot display the jscript attributes like onmouseover, onmouseout and so on, on the <td> generated in my datalist. Could you help me to resolve this problem as well
Working on VS NET 2003 and .NET Framework 1.1
 
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
DataList control in DataListItem Mirek Endys ASP .Net Web Controls 1 11-21-2005 11:13 AM
DataList control in DataListItem Mirek Endys ASP .Net 1 11-21-2005 11:13 AM
Can't retrieve text from DataListItem in DataList ... Phil Corrin ASP .Net 1 09-23-2004 11:31 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM



Advertisments