embed HTML within ASP.net -


i trying format items in shopping cart display in listbox in asp.net using ms visual studio 2010. program displays them elements of each item concatenated string, works less elegant like.

my display function within cartitem class is:

public function display() string return product.productname & "; " & product.productid & ", (" + quantity.tostring() & " @ " & formatcurrency(product.unitprice) & " each) " end function

i told "embed html format string. add table, trs , tds , css." looked "embed html" in w3schools , got nothing seemed relevant. not find in class textbook. when try insert statements tags , visual studio transforms them , . tried putting statements response write follows:

    response.write("<html>")     response.write("<table>")     response.write("<tr>")     response.write("<td>")     response.write("<product.productid>")     response.write("</td>")     response.write("<td>")     response.write("<product.productname>")     response.write("</td>")     response.write("</tr>")     response.write("</table>") 

however, got error on each line saying "response not declared. may inaccessible due protection level". if worked, not response.write appropriate format being printed inside list box.

i try use control (detail view, form view) display cart items, have learned how bind databases, , these items in cart (an object of cartitemlist class, array of cart items), not in database.

any appreciated. need learn not looking solution copy; want understand how right. thank in advance. w

you create usercontrol , implement rendercontents();

public class productgrid :  system.web.ui.webcontrols.webcontrol {     public list<product> datasource {get; set;}      protected override void rendercontents(htmltextwriter output)     {         //here can iterate through datasource , write output         output.write("<html><table>");          foreach(row in this.datasource)         {             output.write(string.format("<td>{0}</td><td>{1}</td></tr>",row.productid, row.productname));         }          output.write("</table></html>");     } } 

now place usercontrol in aspx page, example in div or td. remember if creating user control in separate assembly refer in aspxpage using "register assembly"

<div>      <productgrid width="100%" id="productgrid1" runat="server" /> </div> 

and set datasource in page_load

productgrid1.datasource = ??? ; //from list<product> 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -