中继器控件中的动态控件丢失数据 [英] losing data from dynamic controls in repeater control

查看:42
本文介绍了中继器控件中的动态控件丢失数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

在default.aspx页中

1.添加了添加更多"按钮

Hi Friends,

In the default.aspx page

1. Added the Add more button

<asp:ImageButton ID="ImgAddItem" runat="server" Height="30px" 
                     ImageUrl="~/Images/AddItem.png" onclick="ImgAddItem_Click" Width="30px" 
                     EnableViewState="False" />


2.添加了包含三个控件(下拉列表和两个文本框)的转发器控件


2.Added the repeater control which contains three controls (dropdown and 2 textboxes )

<asp:repeater id="Repeater1" runat="server" >
        <itemtemplate>    
        <tr>
        <td style="padding-removed10px; width:130px;">
            <asp:Label ID="lblitems" runat="server" Font-Names="Verdana" Font-Size="Small" 
                Text="Items" Width="100px">
        </td>
        <td>
            <asp:DropDownList ID="ddlitems" runat="server" AppendDataBoundItems="True" 
                AutoPostBack="True" CssClass="ddl" Width="145px" DataTextField="ItemsName" 
                DataValueField="ItemsId" DataSourceID="SDSItems">
                <asp:ListItem Selected="True" Value="0">--Select--
            
            <asp:RequiredFieldValidator ID="RFV_cash_sfirm1" runat="server" 
                ControlToValidate="ddlitems" Display="Dynamic" 
                ErrorMessage="Please Select Firm" InitialValue="0" SetFocusOnError="True" 
                ValidationGroup="Submit">*
        </td>
        <td style="padding-removed10px; width:130px;">
            <asp:Label ID="lblQuantity" runat="server" Font-Names="Verdana" 
                Font-Size="Small" Text="Quantity" Width="100px">
        </td>
        <td>
            <asp:TextBox ID="txtQuantity" runat="server" AutoPostBack="True" 
                ontextchanged="txtQuantity_TextChanged" Width="140px">
           
        </td>
        <td style="padding-removed10px; width:130px;">
            <asp:Label ID="lblprice" runat="server" Font-Names="Verdana" Font-Size="Small" 
                Text="Price" Width="100px">
        </td>
        <td>
            <asp:TextBox ID="txtprice" runat="server" style="text-align:right" 
                Width="140px">           
        </td>
        <td>
            <asp:ImageButton ID="ImgRemoveItem" runat="server" 
                    ImageUrl="~/Images/cancel.gif" onclick="ImgRemoveItem_Click" Visible="True" />
            
        </td>
    </tr>
       </itemtemplate>


3.当我们点击添加按钮时,将使用以下代码添加新行..


3.When we click on the add button new row will be added ..by using the following code

protected void ImgAddItem_Click(object sender, ImageClickEventArgs e)
    {
        List<int32> _tmpList = ControlsList;
        _tmpList.Add(_tmpList.Count);
        ViewState["ControlsList"] = _tmpList;
        BindTemplate();
    }
private void BindTemplate()
    {
        Repeater1.DataSource = ControlsList;
        Repeater1.DataBind();
    }

private List<int32> ControlsList
    {
        get
        {
            if (ViewState["ControlsList"] != null)
            {
                return ViewState["ControlsList"] as List<int32>;
            }
            else
            {
                List<int32> _tmpList = new List<int32>();
                _tmpList.Add(_tmpList.Count);
                ViewState["ControlsList"] = _tmpList;
                return _tmpList;
            }
        }
        set
        {
            ViewState["ControlsList"] = value;
        }
    }

protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
        {
            BindTemplate();
          
        }      
    }


它的工作正常.但是问题是,

当我们在第一行中输入数据并单击添加更多按钮时,新行正在同时成功创建,我们正在从我之前输入的第一行控件中丢失数据.


请帮我..谢谢Advance


Its working Fine..But the problem is,

When we entered the data in First Row and clicked on the add more button,The new row is creating successfully at the same time ,we are losing the data from the controls of first row which i have entered before..


Pls help me..Thanks in Advance

推荐答案

在设计页面上添加更新面板和触发器

exa-
< asp:
add update panel and triger on design page

exa-
<asp:
UpdatePanel runat="server" ID="PurchaseUpdate" UpdateMode="Conditional" ChildrenAsTriggers="true">
 <Triggers > </Triggers>
<ContentTemplate


>
并在内容占位符结束后关闭标签


>
and close the tag after end withen content place holder


这篇关于中继器控件中的动态控件丢失数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆