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

来源:互联网 发布:绝境求生画面优化补丁 编辑:程序博客网 时间:2024/06/01 10:30

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" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <title>物品分类</title>    <link href="/Themes/Styles/Site.css" rel="stylesheet" type="text/css" />    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>    <script type="text/javascript">        $(function () {            divresize(90);            FixedTableHeader("#table1", $(window).height() - 118);        })    </script></head><body>    <form id="form1" runat="server">    <div class="btnbartitle">        <div>           分类信息        </div>    </div>    <div class="btnbarcontetn">        <div style="text-align: right;">            <uc1:LoadButton ID="LoadButton1" runat="server" />        </div>    </div>          <table>    <tr>    <td valign="top" style="width:25%;">        <asp:GridView ID="dgvItemList" runat="server"  AutoGenerateColumns="False"><%-view控件-%>            <Columns>                <asp:BoundField DataField="id" HeaderText="id"/>                <asp:BoundField DataField="itemCode" HeaderText="编号" />                <asp:BoundField DataField="itemName" HeaderText="名称" />                <asp:BoundField DataField="SpecCode" HeaderText="规格" />                <asp:BoundField DataField="UnitCode" HeaderText="单位" />            </Columns>        </asp:GridView>         <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />           <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>    </td>    <td style="width:75%;">        <table id="table1" class="grid" singleselect="true">            <thead>                <tr>                    <td style="width: 50px; text-align: center;">                        操作                     </td>                                 <td style="width: 150px; text-align: center;">                        名称                    </td>                     <td style="width: 150px; text-align: center;">                        规格                    </td>                    <td style="width: 150px; text-align: center;">                        消耗                    </td>                    <td style="width: 150px; text-align: center;">                        单位                    </td>                    <td>                        计划数量                    </td>                </tr>            </thead>            <tbody>                <asp:Repeater ID="it_Item" runat="server" ><%-repeater控件-%>>                    <ItemTemplate>                        <tr>                           <td style="width: 50px; text-align: left;">                                <asp:Button ID="btnDel" runat="server" Text="删除"  OnClick="btnDel_Click" CommandArgument='<%#Eval("id")%>'/>                            </td>                            <td style="width: 150px; text-align: center;">                                <asp:Label ID="lblId" runat="server" Text='<%#Eval("id")%>' Visible="false"></asp:Label>                                <asp:Label ID="lblItemName" runat="server" Text='<%#Eval("ItemName")%>'></asp:Label>                            </td>                            <td style="width: 150px; text-align: center;">                                <asp:Label ID="lblSpecCode" runat="server" Text='<%#Eval("SpecCode")%>'></asp:Label>                            </td>                            <td style="width: 150px; text-align: center;">                                <asp:Label ID="lblLastMonth" runat="server" Text='<%#Eval("LastMonth")%>'></asp:Label>                            </td>                                                         <td style="width: 150px; text-align: center;">                                <asp:Label ID="lblUnitCode" runat="server" Text='<%#Eval("UnitCode")%>'></asp:Label>                            </td>                            <td >                                <asp:TextBox ID="txtPurchNum" runat="server" Text='<%#Eval("PurchNum")%>'></asp:TextBox>                            </td>                        </tr>                    </ItemTemplate>                 </asp:Repeater>            </tbody>        </table>                </td>    </tr>    </table>     </form></body></html>

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.内容不完善,有待提高。



0 0