如何从Repeater获取更新的Textbox值?

时间:2012-11-30 15:21:37

标签: c# asp.net gridview repeater

我有一个repeater控件,如下所示。它有一个textbox控件。单击save button时,我需要从文本框中获取更新的文本。我有以下代码;但是当我拿到文本框文本时,它给了我旧的价值。

我们如何获得更新的文本?

代码背后

    protected void Save_Click(object sender, EventArgs e)
    {

        foreach (RepeaterItem item in repReports.Items )
        {
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem )
            {

                string updatedEmail = ((TextBox)item.Controls[5]).Text;
                string originalEmail = ((HiddenField)item.Controls[7]).Value;


            }
        }
    }

控制加价

  <div class="repeaterTableBorder">
                <asp:Repeater ID="repReports" runat="server">
                    <ItemTemplate>
                        <div id="repeaterIdentifier" class="repeaterIdentifier">
                            <div class="reportTitle">
                                <%# Eval("ReportName") + ":"%>
                                <asp:HiddenField ID="hdnLastChangeTime" runat="server" Value= '<%# ((DateTime)Eval("RecordSelectionTime")).ToString("MM/dd/yyyy hh:mm:ss.fff tt")%>' />
                                <asp:HiddenField ID="hdnReportID" runat="server" Value='<%# Eval("ReportTypeCode")%>' />
                            </div>
                            <div class="reportFrequency">
                                 <%# " Frequency - Weekly" %> 
                            </div>
                        </div>
                        <div class="reportContent">
                            <div class="repeaterLine">
                                <asp:TextBox ID="txtEmailRecipients" runat="server" class="textEdit" 
                                    Text='<%# Eval("ExistingRecipients") %>'
                                    TextMode="MultiLine"></asp:TextBox>
                                 <asp:HiddenField ID="hdnOriginalRecipients" runat="server" Value='<%# Eval("ExistingRecipients")%>' />
                            </div>
                        </div>

                    </ItemTemplate>
                </asp:Repeater>
            </div>

1 个答案:

答案 0 :(得分:8)

我假设您在回发时也将Repeater绑定到DataSource。你应该只做if(!IsPostBack)。否则,值将被覆盖。

protected void Page_Load(Object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        // databinding code here
    }
}