如何向已存在元素的泛型中添加一个新元素?

epui2008 epui2008 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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" %>

<!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>
...全文

相关推荐

【泛型】Java中的泛型,泛型类,泛型接口,泛型方法,泛型擦除

这篇文章总结一下Java中的泛型相关知识点,包括:泛型概念、泛型优缺点、泛型通配符、泛型上下界、泛型使用(泛型类、泛型接口、泛型方法)、泛型擦除等内容。 一、泛型概念 (1)什么是泛型 什么是泛型??? 泛型(Generic),是一种参数化数据类型,它允许我们在编写程序代码的时候不用具体指定需要什么数据类型,而是等到具体使用的时候,将数据类型以参数的形式传递给程序,这就是泛型程序设计。 (2)为什么需要泛型 我们来看看下面这个栗子 假设现在有个需求,通过集合保存元素,需要保存String字

Mr.小朱同学

A Survey of Vision-Language-Action Models for Robot Manipulation_视觉-语言-动作模型综述.md

ArxivReview学术论文研究综述,详细内容可访问:https://www.arxivreview.com/surveys

ArxivReview8

A Survey of Multimodal Brain Tumor Segmentation Methods_多模态脑肿瘤分割方法综述.md

ArxivReview学术论文研究综述,详细内容可访问:https://www.arxivreview.com/surveys

Jessica Zhan

A Survey of Neuromorphic Hardware and SNN Acceleration_神经形态硬件与SNN加速综述.md

ArxivReview学术论文研究综述,详细内容可访问:https://www.arxivreview.com/surveys

Jessica Zhan

A Survey of Self-Supervised and Foundation Models for 3D Medical Imaging_3D医学影像自监督与基础模型综述.md

ArxivReview学术论文研究综述,详细内容可访问:https://www.arxivreview.com/surveys

ArxivReview8
评论 9
收藏 已收藏
分享
返回顶部
epui2008
.NET社区 62,275 成员 668,968 内容