c# - Show query values in a form of list using li tag -


i have following c# code:

try {     conn.open();     string sql = "my query returns n rows";      oraclecommand cmd = new oraclecommand(sql, conn);     cmd.commandtype = commandtype.text;      oracledatareader dr = cmd.executereader();      while (dr.read())      {         mylistbox.items.add(dr.getstring(0));     } } catch (exception ex) {     label1.text = "## error: " + ex.message; } 

on .aspx page, instead of using listbox, want each value in list item using li tag. i've been searching can't find if it's possible using loop , if it's possible, don't have idea on how .

note: honestly, requirement, need use li tag this.

option 1:

better way user datarepeater control.

somewhere have class:

class item {     public string description { get; set; }      item(string description)     {         this.description = description;     } } 

here prepare list of objects(item):

list<item> items  = new list<item>(); while (dr.read())  {     items.add(new item(dr.getstring(0))); }  repeater1.datasource = items; repeater1.databind(); 

and here datarepeater code:

<ul> <asp:repeater runat="server" id="repeater1">    <itemtemplate>        <li>'<%# eval("description") %>'</li>    </itemtemplate> </asp:repeater> </ul> 

option 2:

you can prepare custom html , assign control display.

change while loop:

while (dr.read())  {     mylistbox.items.add(dr.getstring(0)); } 

to this:

string html = "<ul>"; while (dr.read())  {     html += "<li>" + dr.getstring(0) + "</li>"; } html += "</ul>";  divlist.innerhtml = html; 

where divlist regular div can place on .aspx page , add attribute runat="server".

<div id="divlist" runat="server"></div> 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -