Académique Documents
Professionnel Documents
Culture Documents
c# source: cs\datagrid4.aspx
vb source: vb\datagrid4.aspx
jscript source: js\datagrid4.aspx
vj# source: vjs\datagrid4.aspx
<html>
<script language="vb" runat="server">
dim dt as datatable
dim dr as datarow
dim i as integer
'create a datatable
dt = new datatable
dt.columns.add(new datacolumn("integervalue", gettype(integer)))
dt.columns.add(new datacolumn("stringvalue", gettype(string)))
dt.columns.add(new datacolumn("datetimevalue", gettype(datetime)))
dt.columns.add(new datacolumn("boolvalue", gettype(boolean)))
dt.columns.add(new datacolumn("currencyvalue", gettype(double)))
end function
' e.item is the row of the table where the command fired
' for bound columns the value is stored in the text property of tablecell
dim itemcell as tablecell = e.item.cells(2)
dim pricecell as tablecell = e.item.cells(3)
dim item as string = itemcell.text
dim price as string = pricecell.text
end sub
</script>
<body>
<form runat=server>
<table cellpadding="5">
<tr valign="top"><td>
<b>product list</b>
<asp:datagrid id="mydatagrid" runat="server"
bordercolor="black"
borderwidth="1"
gridlines="both"
cellpadding="3"
cellspacing="0"
font-name="verdana"
font-size="8pt"
headerstyle-backcolor="#aaaadd"
autogeneratecolumns="false"
onitemcommand="grid_cartcommand"
>
<columns>
<asp:buttoncolumn headertext="add to cart" text="add"
commandname="addtocart" />
<asp:buttoncolumn headertext="remove from cart" text="remove"
commandname="removefromcart" />
<asp:boundcolumn headertext="item" datafield="stringvalue"/>
<asp:boundcolumn headertext="price" datafield="currencyvalue"
dataformatstring="{0:c}" itemstyle-horizontalalign="right" />
<asp:boundcolumn headertext="assembly required?"
datafield="boolvalue"/>
</columns>
</asp:datagrid>
</td><td>
<b>shopping cart</b>
<asp:datagrid id="shoppingcart" runat="server"
bordercolor="black"
borderwidth="1"
cellpadding="3"
font-name="verdana"
font-size="8pt"
headerstyle-backcolor="#aaaadd"
/>
</td></tr>
</table>
</form>
</body>
</html>