使用临时表在list和reapter之间做数据的传递(双击view,数据进入到repeater中,点击reapter中的删除按钮进行删除)

1.效果图

使用临时表在list和reapter之间做数据的传递(双击view,数据进入到repeater中,点击reapter中的删除按钮进行删除)_第1张图片

2.前台代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="RM.Web.Project.SuppPurchPlan.Edit" %>


<%@ Register Src="../../UserControl/LoadButton.ascx" TagName="LoadButton" TagPrefix="uc1" %>




    物品分类
    
    
    
    


    
分类信息
<%-view控件-%> <%-repeater控件-%>>
操作 名称 规格 消耗 单位 计划数量

3.后台代码

using RM.Busines.DAL;
using RM.Busines.IDAO;
using RM.Common.DotNetUI;
using RM.Web.App_Code;
using RM.Web;
using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using RM.Web.UserControl;
using System.Text;
using System.Collections.Generic;
using RM.Common.DotNetCode;
using System.Text;

namespace RM.Web.Project.SuppPurchPlan
{
    public partial class Edit : PageBase
    {
        #region 声明变量
        private sysBase_IDAO itembaseidao = new sysBase_Dal();
        protected HtmlHead Head1;
        protected HtmlForm form1;
        protected LoadButton LoadButton1;
        protected Repeater ct_Item;
        private RM.Busines.IDAO.IProject.IsuppPurchBill suppPurchBill = new RM.Busines.DAL.Project.suppPurchBill();
        #endregion

        #region 页面初始化
        protected void Page_Load(object sender, EventArgs e)
        {

            dgvItemList.RowDataBound += new GridViewRowEventHandler(dgvItemList_RowDataBound);

            //绑定物资信息
            if (!base.IsPostBack)
            {
                this.DataBindGrid();
            }
        }
        #endregion

        #region 删除物资
        //删除已选择内容
        protected void btnDel_Click(object sender, EventArgs e)
        {
            Button btnedit = (Button)sender;
            string icount = btnedit.CommandArgument.ToString();


            DataTable dt = CreateTable();


            for (int i = 0; i < it_Item.Items.Count; i++)
            {
                Label lid = (Label)this.it_Item.Items[i].FindControl("lblId");
                Label lItemName = (Label)this.it_Item.Items[i].FindControl("lblItemName");
                Label lSpecCode = (Label)this.it_Item.Items[i].FindControl("lblSpecCode");
                Label lLastMonth = (Label)this.it_Item.Items[i].FindControl("lblLastMonth");
                Label lUnitCode = (Label)this.it_Item.Items[i].FindControl("lblUnitCode");
                TextBox txtPurchNum = (TextBox)this.it_Item.Items[i].FindControl("txtPurchNum");


                if (lid.Text.ToString() != icount)
                {
                    DataRow drow = default(DataRow);
                    drow = dt.NewRow();
                    drow["id"] = lid.Text.ToString();
                    drow["ItemName"] = lItemName.Text.ToString();
                    drow["SpecCode"] = lSpecCode.Text.ToString();
                    drow["LastMonth"] = lLastMonth.Text.ToString();
                    drow["UnitCode"] = lUnitCode.Text.ToString();
                    drow["PurchNum"] = txtPurchNum.Text.ToString();
                    dt.Rows.Add(drow);
                }
            }
            ControlBindHelper.BindRepeaterList(dt, this.it_Item);
        }
        #endregion

        #region 绑定物资信息
        private void DataBindGrid()
        {
            DataTable dt = new DataTable();
            dt = suppPurchBill.GetsuppPurchBill();//BindGridViewList   //select * from XXXX
            ControlBindHelper.BindGridNoData(dt, dgvItemList);       //绑定数据
        }
        #endregion

        #region 创建自定义表
        public DataTable CreateTable()
        {
            DataTable dt = new DataTable();
            DataColumn dtcol0 = new DataColumn("id", Type.GetType("System.String"));
            dt.Columns.Add(dtcol0);
            DataColumn dtcol1 = new DataColumn("ItemName", Type.GetType("System.String"));
            dt.Columns.Add(dtcol1);
            DataColumn dtcol2 = new DataColumn("SpecCode", Type.GetType("System.String"));
            dt.Columns.Add(dtcol2);
            DataColumn dtcol3 = new DataColumn("LastMonth", Type.GetType("System.String"));
            dt.Columns.Add(dtcol3);
            DataColumn dtcol4 = new DataColumn("UnitCode", Type.GetType("System.String"));
            dt.Columns.Add(dtcol4);
            DataColumn dtcol5 = new DataColumn("PurchNum", Type.GetType("System.String"));
            dt.Columns.Add(dtcol5);
            return dt;
        }
        #endregion

        #region GridView双击事件
        void dgvItemList_RowDataBound(object sender, GridViewRowEventArgs e)  //view的双击事件
        {
            try
            {
                for (int i = 0; i < dgvItemList.Rows.Count; i++)
                {
                    string ID = "";
                    ID = dgvItemList.Rows[i].Cells[0].Text.ToString();
                    dgvItemList.Rows[i].Attributes.Add("ondblclick", "document.getElementById('TextBox1').value=" + ID + ";document.getElementById('Button1').click();");//双击事件时触发button的click事件。
                }
            }
            catch
            {

            }
        }
        #endregion

        #region 绑定选择的物资信息
        protected void get_ManuCreatTable()   //
        {
            //判断是否选择了
            for (int i = 0; i < it_Item.Items.Count; i++)
            {
                Label lid = (Label)this.it_Item.Items[i].FindControl("lblId");
                if (TextBox1.Text.Trim() == lid.Text.Trim())
                {
                    return;
                }
            }

            DataTable dt = CreateTable();
            //首先附加原有信息
            for (int i = 0; i < it_Item.Items.Count; i++)
            {
                Label lid = (Label)this.it_Item.Items[i].FindControl("lblId");
                Label lItemName = (Label)this.it_Item.Items[i].FindControl("lblItemName");
                Label lSpecCode = (Label)this.it_Item.Items[i].FindControl("lblSpecCode");
                Label lLastMonth = (Label)this.it_Item.Items[i].FindControl("lblLastMonth");
                Label lUnitCode = (Label)this.it_Item.Items[i].FindControl("lblUnitCode");
                TextBox txtPurchNum = (TextBox)this.it_Item.Items[i].FindControl("txtPurchNum");

                DataRow drow = default(DataRow);
                drow = dt.NewRow();
                drow["id"] = lid.Text.ToString();
                drow["ItemName"] = lItemName.Text.ToString();
                drow["SpecCode"] = lSpecCode.Text.ToString();
                drow["LastMonth"] = lLastMonth.Text.ToString();
                drow["UnitCode"] = lUnitCode.Text.ToString();
                drow["PurchNum"] = txtPurchNum.Text.ToString();
                dt.Rows.Add(drow);
            }

            //获取选择的物资信息
            DataTable dt1 = suppPurchBill.GetitemList(TextBox1.Text.Trim());
            //再附加新增信息
            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                DataRow drow = default(DataRow);
                drow = dt.NewRow();
                drow["id"] = dt1.Rows[i]["id"].ToString();
                drow["ItemName"] = dt1.Rows[i]["ItemName"].ToString();
                drow["SpecCode"] = dt1.Rows[i]["SpecCode"].ToString();
                drow["LastMonth"] = "0";
                drow["UnitCode"] = dt1.Rows[i]["UnitCode"].ToString();
                drow["PurchNum"] = "0";
                dt.Rows.Add(drow);
            }
            ControlBindHelper.BindRepeaterList(dt, this.it_Item);
        }
        #endregion

        #region 隐藏处理控件
        protected void Button1_Click(object sender, EventArgs e)
        {
            get_ManuCreatTable();
        }
        #endregion
    }
}
4.完成后对前台显示的textbox和button 做隐藏处理,然后找美工设计一下页面就OK了


5.内容不完善,有待提高。



你可能感兴趣的:(C#)