c# - Grouping with specific attribute in Listview -


guys have asp:listview item.i want read data database , want categorize them below. http://prntscr.com/8rhpcb codelike below:

<asp:listview id="listview1" runat="server" datakeynames="id" datasourceid="sqldatasource1"          itemplaceholderid="iph" >         <itemtemplate>             <table id="item_table" border="1">                 <tr style="background-color: #e0ffff;color: #333333;">                     <td>                         <asp:label id="idlabel" runat="server"                              text='<%# eval("id") %>' />                     </td>                     <td>                         <asp:label id="namelabel" runat="server"                              text='<%# eval("name") %>' />                     </td>                     <td>                         <asp:label id="surnamelabel" runat="server"                              text='<%# eval("surname") %>' />                     </td>                     <td>                         <asp:label id="sexlabel" runat="server"                              text='<%# eval("sex") %>' />                     </td>                     <td>                         <asp:label id="emaillabel" runat="server"                              text='<%# eval("email") %>' />                     </td>                     <td>                         <asp:label id="citylabel" runat="server"                              text='<%# eval("city") %>' />                     </td>                     <td>                         <asp:label id="agelabel" runat="server"                              text='<%# eval("age") %>' />                     </td>                 </tr>            </table>          </itemtemplate>          <layouttemplate>             <table id="table1" runat="server" border="1"               style="background-color: #ffffff;border-color: #999999;border-style:none;                 border-width:1px;font-family: verdana, arial, helvetica, sans-serif;">                 <tr runat="server" style="background-color: #e0ffff;color: #333333;">                          <th id="th1" style="width:130px" runat="server">id</th>                         <th id="th2" style="width:130px" runat="server">name</th>                         <th id="th3" style="width:130px" runat="server">surname</th>                         <th id="th4" style="width:130px" runat="server">sex</th>                         <th id="th5" style="width:130px" runat="server">email</th>                         <th id="th6" style="width:130px" runat="server">city</th>                         <th id="th7" style="width:130px" runat="server">age</th>                 </tr>                 <tr>                  </tr>             </table>              <table id="table2" runat="server" border="1"               style="background-color: #ffffff;border-color: #999999;border-style:none;border-width:1px;font-family: verdana, arial, helvetica, sans-serif;">                 <tr id="tr2" runat="server" style="background-color: #e0ffff;color: #333333;">                         <th id="th8"  style="width:130px" runat="server">id</th>                         <th id="th9"  style="width:130px" runat="server">name</th>                         <th id="th10" style="width:130px" runat="server">surname</th>                         <th id="th11" style="width:130px" runat="server">sex</th>                         <th id="th12" style="width:130px" runat="server">email</th>                         <th id="th13" style="width:130px" runat="server">city</th>                         <th id="th14" style="width:130px" runat="server">age</th>                 </tr>                 <tr runat="server" id="iph"></tr>             </table>          </layouttemplate>      </asp:listview> 

i can using 2 listview want in 1 listview.it can possible?if possible can explain me detail or code example?

finally find way this.code below:

<asp:listview id="listview1" runat="server" datakeynames="id" datasourceid="sqldatasource1"          itemplaceholderid="iph" >         <itemtemplate>             <table id="item_table" border="1">                  <%# addtitle() %>                 <tr style="background-color: #e0ffff;color: #333333;">                     <td>                         <asp:label id="idlabel" runat="server"                              text='<%# eval("id") %>' />                     </td>                     <td>                         <asp:label id="namelabel" runat="server"                              text='<%# eval("name") %>' />                     </td>                     <td>                         <asp:label id="surnamelabel" runat="server"                              text='<%# eval("surname") %>' />                     </td>                     <td>                         <asp:label id="sexlabel" runat="server"                              text='<%# eval("sex") %>' />                     </td>                     <td>                         <asp:label id="emaillabel" runat="server"                              text='<%# eval("email") %>' />                     </td>                     <td>                         <asp:label id="citylabel" runat="server"                              text='<%# eval("city") %>' />                     </td>                     <td>                         <asp:label id="agelabel" runat="server"                              text='<%# eval("age") %>' />                     </td>                 </tr>            </table>          </itemtemplate>          <layouttemplate>             <table id="table1" runat="server" border="1"               style="background-color: #ffffff;border-color: #999999;border-style:none;border-width:1px;font-family: verdana, arial, helvetica, sans-serif;">                 <tr runat="server" style="background-color: #e0ffff;color: #333333;">                         <th id="th1" style="width:130px" runat="server">id</th>                         <th id="th2" style="width:130px" runat="server">name</th>                         <th id="th3" style="width:130px" runat="server">surname</th>                         <th id="th4" style="width:130px" runat="server">sex</th>                         <th id="th5" style="width:130px" runat="server">email</th>                         <th id="th6" style="width:130px" runat="server">city</th>                         <th id="th7" style="width:130px" runat="server">age</th>                 </tr>                 <tr runat="server" id="iph">                  </tr>             </table>          </layouttemplate>      </asp:listview> 

and in code behind:

string lastvalue = "";     protected string addtitle() {          string newvalue = eval("sex").tostring();          if (newvalue != lastvalue)         {             lastvalue = newvalue;             return string.format("<tr class=" + "group" + "><td colspan=" + "7" + ">gender:{0}</td></tr>", newvalue);         }         else {             return string.empty;         }     } 

first of all,for grouping data pic, data records must ordered.after in addtitle method every time getting record database,it controls gender type if different previous gender type,it adds column table "men list" or "women list".i hope others have problems me.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -