c# - How to Repeat Header in Datalist when Repeating Colums=2 -
my requirement display datalist below
header1 header2 header1 header2 1 value 1 3 value 3 2 value 2 4 value 4
but i'm unable repeat header section of data list. complete code stuff datalist
<asp:datalist id="datalstprofilecount" runat="server" repeatcolumns="2" repeatdirection="horizontal" repeatlayout="table" showheader="true" onitemdatabound="datalstprofilecount_itemdatabound"> <headertemplate> <table border="0" cellpadding="0" cellspacing="0" bordercolor="#e1e1e0" style="border: solid 1px #e1e1e0; font-family: segoe ui; font-size: 12px; font-weight: bold; width: 400px"> <tr style="font-size: 13px; background: #ffedc2; border-bottom: 1px solid #eba602; border-left: 1px solid #d6d6d6; font-weight: 600; font-size: 13px; padding: 10px 8px; color: #c82124;"> <td style="width: 80px; color: #c84241; text-align: center; padding: 6px"> name </td> <td style="width: 100px; color: #c84241; text-align: center; padding: 6px"> total count </td> <td style="width: 100px; color: #c84241; text-align: center; padding: 6px"> active members count </td> </tr> </table> </headertemplate> <itemtemplate> <table border="0" cellpadding="0" cellspacing="0" bordercolor="#e1e1e0" style="border: solid 1px #e1e1e0; font-family: segoe ui; font-size: 12px; font-weight: bold; width: 400px; margin: -1px"> <tr style="font-size: 12px; vertical-align: middle; color: #9d9d9c;"> <td style="text-align: left; width: 80px; color: #333333; padding: 6px"> <asp:label id="label2" runat="server" text='<%#eval("name") %>'></asp:label> </td> <td style="text-align: right; width: 100px; color: #333333; padding: 6px"> <asp:label id="lbltotalcount" runat="server" text='<%#eval("totalcount") %>'></asp:label> </td> <td style="text-align: right; width: 100px; color: #333333; padding: 6px"> <asp:label id="lblactivememberscount" runat="server" text='<%#eval("activememberscount") %>'></asp:label> </td> </tr> </table> </itemtemplate> <footertemplate> <table border="0" cellpadding="0" cellspacing="0" style="padding-top: 20px" align="center"> <tr> <td style="font-size: 14px"> total count: </td> <td style="padding-left: 10px"> <asp:label id="lblprofilecount" runat="server" text="" forecolor="#c82124" font-size="14px"></asp:label> </td> </tr> <tr> <td style="font-size: 14px"> active members count: </td> <td style="padding-left: 10px"> <asp:label id="lblmembercount" runat="server" text="" forecolor="#c82124" font-size="14px"></asp:label> </td> </tr> </table> </footertemplate> </asp:datalist>
please of me.. , thank in advance...
header never repeat itself, make header html part of item template. per .net controls implementation, header head of list come once, item template repeated based on number of items present in data source , comes footer..
something this:
<asp:datalist id="datalstprofilecount" runat="server" repeatcolumns="2" repeatdirection="horizontal" repeatlayout="table" showheader="true" onitemdatabound="datalstprofilecount_itemdatabound"> <headertemplate> </headertemplate> <itemtemplate> //header section //data </itemtemplate> </asp:datalist>
if still have confusion share whole data list header section , data section mentioned in comment, provide updated code..
updated answer:
<asp:datalist id="datalstprofilecount" runat="server" repeatcolumns="2" repeatdirection="horizontal" repeatlayout="table" showheader="true" onitemdatabound="datalstprofilecount_itemdatabound"> <headertemplate> </headertemplate> <itemtemplate> <table border="0" cellpadding="0" cellspacing="0" bordercolor="#e1e1e0" style="border: solid 1px #e1e1e0; font-family: segoe ui; font-size: 12px; font-weight: bold; width: 400px; margin: -1px"> <tr style="font-size: 13px; background: #ffedc2; border-bottom: 1px solid #eba602; border-left: 1px solid #d6d6d6; font-weight: 600; font-size: 13px; padding: 10px 8px; color: #c82124; visibility: hidden;" id="trheader" runat="server"> <td style="width: 80px; color: #c84241; text-align: center; padding: 6px"> name </td> <td style="width: 100px; color: #c84241; text-align: center; padding: 6px"> total count </td> <td style="width: 100px; color: #c84241; text-align: center; padding: 6px"> active members count </td> </tr> <tr style="font-size: 12px; vertical-align: middle; color: #9d9d9c;"> <td style="text-align: left; color: #333333; padding: 6px"> <asp:label id="label2" runat="server" text='<%#eval("name") %>'></asp:label> </td> <td style="text-align: right; color: #333333; padding: 6px"> <asp:label id="lbltotalcount" runat="server" text='<%#eval("totalcount") %>'></asp:label> </td> <td style="text-align: right; color: #333333; padding: 6px"> <asp:label id="lblactivememberscount" runat="server" text='<%#eval("activememberscount") %>'></asp:label> </td> </tr> </table> </itemtemplate> <footertemplate> <table border="0" cellpadding="0" cellspacing="0" style="padding-top: 20px" align="center"> <tr> <td style="font-size: 14px"> total count: </td> <td style="padding-left: 10px"> <asp:label id="lblprofilecount" runat="server" text="" forecolor="#c82124" font-size="14px"></asp:label> </td> </tr> <tr> <td style="font-size: 14px"> active members count: </td> <td style="padding-left: 10px"> <asp:label id="lblmembercount" runat="server" text="" forecolor="#c82124" font-size="14px"></asp:label> </td> </tr> </table> </footertemplate> </asp:datalist>
on server side add code:
protected void datalstprofilecount_itemdatabound(object sender, datalistitemeventargs e) { if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem) { if(e.item.itemindex <=1) { var headerrow = (system.web.ui.htmlcontrols.htmltablerow)e.item.findcontrol("trheader"); if(headerrow != null) { headerrow.style.add(htmltextwriterstyle.visibility, ""); } } } }
you might need changes in styles can achieved.
Comments
Post a Comment