如何向已存在元素的泛型中添加一个新元素?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class newadmin_kucun_Default : System.Web.UI.Page
{
string _conn = WebConfigurationManager.ConnectionStrings["proconnectionstring"].ConnectionString;
public List<int> dingdan = new List<int>();
public int jishu;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
jishu = 0;
Label1.Text = "这是页面firstload";
}
Label1.Text = "这是页面reload";
jishu = jishu + 1;
}
protected void caozuo(object sender, CommandEventArgs e)
{
if (e.CommandName == "show")
{
dingdan.Add(int.Parse(e.CommandArgument.ToString()));
Label1.Text = Label1.Text + jishu.ToString();
ListBox1.DataSource = dingdan;
ListBox1.DataBind();
// 为什么每次listbox 只显示一条id记录呢
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="newadmin_kucun_Default" %>泛型 产品 updatepanel c#
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.tab1 {
width:580px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate><div style="height:300px;overflow:scroll;width:600px;">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table class="table2" >
<tr>
<th>产品ID</th>
<th>产品名</th>
<th>库存数量</th>
<th>添加</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("id") %></td>
<td><%#Eval("proname") %></td>
<td><%#Eval("kucun") %></td>
<td>
<asp:LinkButton ID="LinkButton3" runat="server" CommandArgument='<%#Eval("id") %>' CommandName="show" OnCommand="caozuo" >添加</asp:LinkButton></td>
</tr>
</ItemTemplate>
<footerTemplate>
</table>
</footerTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:proconnectionstring %>" SelectCommand="SELECT [proname], [kucun], [id] FROM [kucun2013]"></asp:SqlDataSource></div>
<br />
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
<br /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>