esempio che avevo sotto mano e che avevo già fatto nel forum da qualche parte:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
int _sum = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
_sum += ((Product)e.Row.DataItem).Stock.GetValueOrDefault();
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
Literal _lit = new Literal();
_lit.Text = _sum.ToString();
e.Row.Controls[0].Controls.Add(_lit);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="LinqDataSource1"
onrowdatabound="GridView1_RowDataBound" ShowFooter="True"
AllowPaging="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:TemplateField InsertVisible="False" SortExpression="ProductID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Stock") %>'></asp:Label>
<asp:DropDownList ID="drop1" runat="server" SelectedValue ='<%# Eval("Stock") %>' >
<asp:ListItem >0</asp:ListItem>
<asp:ListItem >1</asp:ListItem>
<asp:ListItem >2</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductID") %>'></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Stock") %>'></asp:TextBox>
<asp:DropDownList ID="drop1" runat="server" SelectedValue ='<%# Bind("Stock") %>' >
<asp:ListItem >0</asp:ListItem>
<asp:ListItem >1</asp:ListItem>
<asp:ListItem >2</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="ProductDataContext" TableName="Products"
EnableDelete="True" EnableInsert="True" EnableUpdate="True">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
Product è un oggetto che ho usato io per memorizzare le informazioni
ciao marco
Modificato da nostromo il 24 luglio 2008 18.50 -