问题
<FooterTemplate>
<tr style="background-color:Orange;">
< td width="6%" align="center" id = "tdFooter" runat = "server" colspan = "3">
</td>
</tr>
</FooterTemplate>
I have a repeater control in which i have this footer template. All i want is to change the colspan of tdFooter at itemdatabound event(c#) on the basis of some if clauses.How can i do the same?
if (e.Item.ItemType == ListItemType.Footer)
{
if(role = 0)
{
//tdfooter colspan should be 3
}
else
{
//tdfoote colspan should be 2
}
}
回答1:
I would add a runat to the td tag
<td runat="server" id="tdControl">
in the itemdatabound:
var td = (HtmlTableCell)e.Item.FindControl("tdControl");
td.Attributes.Add("colspan", myNumber);
来源:https://stackoverflow.com/questions/15849957/how-to-change-colspan-of-a-td-dynamically-in-c