开发者

Edit Textbox in Repeater

I have a repeater with a textbox inside. I am trying to edit the information inside the textbox, retrieve the new data, and write to the DB. With my code its giving me the original info that was in the box. Not the new information that I have added. Here is my code

html:

<asp:LinkButton id="saveReviewLinkButton" text="Save" runat="server" onCommand="saveReviewLinkButton_OnCommand" />
<table>
 <asp:Re开发者_如何学Gopeater id="ReviewRepeater" runat="server" onItemDataBound="ReviewRepeater_ItemDataBound">
            <itemtemplate>
              <tr >
                <td ><asp:TextBox id="titleLabel" runat="server" width="200px" textMode="MultiLine"/></td>
              </tr>
            </itemtemplate>
</table>

c#:

protected void ReviewRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
    {
      Review review = (Review)e.Item.DataItem;
      TextBox titleLabel = (TextBox)e.Item.FindControl("titleLabel");
      titleLabel.Text = review.Title;
    }
}



  protected void saveReviewLinkButton_OnCommand(object sender, EventArgs e)
  {
     TextBox titleLabel = new TextBox();

     foreach (RepeaterItem dataItem in ReviewRepeater.Items)
       {
          titleLabel = (TextBox)dataItem.FindControl("titleLabel");
          string newInfo = titleLabel.Text;
       }
  }


Please make sure, you are binding the data to the repeater by checking in page load

if(!IsPostBack)
  BindData();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜