How to change colspan of a td dynamically in c#?

假如想象 提交于 2019-12-10 18:39:44

问题


  <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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!