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("color
range;");
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(\"ItemsList\").rows.length;i++)");
sb_script.Append("{");
sb_script.Append("document.all(\"ItemsList\").rows
.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.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.