asp.net - Populating listview web control from a datareader -


this first time trying use listviews , i've spent better part of day beating head against wall trying make work. i've created listview i'm trying populate data oracle db. i'm trying use datareader populate listview i'm having hard time making work. there lot out there on accomplishing listview form control not web control. appreciated.

the furthest i've been able this:

while reader.read     dim obj new listviewdataitem((reader(0)), (reader(1)))    lsvgeneratedforms.items.add(obj)  end while 

but allows me read 2 objects (i need pull in 4) , run type conversion error db contains string & date datatypes.

markup listview:

<div class="generatedformsdivstyle" style="height:300px; overflow:scroll"> <asp:listview runat="server" id="lsvgeneratedforms">     <layouttemplate>         <table id="tblformlist" border="0" cellpadding="0" cellspacing="0">            <tr style="background-color:#ccdaeb">                <th align="left">                <asp:label id="hdragreeno" runat="server" text="agreement no"/>    </th>                <th align="left">                <asp:label id="hdrgendate" runat="server" text="date generated"/></th>                <th align="left">                <asp:label id="hdrleacct" runat="server" text="legal entity account"/></th>                <th align="left">                <asp:label id="hdrstatus" runat="server" text="status"/></th>            </tr>            <tr id="itemplaceholder" runat="server"></tr>         </table>     </layouttemplate>     <itemtemplate>         <tr>             <td>             <asp:label runat="server" id="lblagreeno"><%#eval("agreement_num")%></asp:label></td>             <td>             <asp:label runat="server" id="lblgendate"><%#eval("gen_date")%></asp:label></td>             <td>              <asp:label runat="server" id="lblleacct"><%#eval("le_account")%></asp:label></td>             <td>              <asp:label runat="server" id="lblstatus"><%#eval("status")%></asp:label></td>                             </tr>     </itemtemplate> </asp:listview> </div> 

to illustrate example, create class:

public class myitem      public property agreement_num string     public property gen_date string     public property le_account string     public property status string end class 

this matches fields populating in <itemtemplate>.

next, map results reader class:

dim myitems list(of mydataitem) = new list(of mydataitem)()  while (reader.read())     dim newitem new mydataitem { .agreement_num = reader(0).tostring(), .gen_date = reader(1).tostring(), .le_account = reader(2).tostring(), .status = reader(2).tostring() }     myitems.add(newitem) end while   

then can bind list:

mylistview.datasource = myitems mylistview.databind() 

the above code example - need adjust accordingly code. important thing ensure collection of objects binding has corresponding field names used in markup.


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -