文本框在Repeater_ItemCommand上回发后丢失其值。 [英] Textbox Losing its Value after Postback on Repeater_ItemCommand.

查看:50
本文介绍了文本框在Repeater_ItemCommand上回发后丢失其值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Textbox在Repeater_ItemCommand上回发后丢失其值。



有一个Linkbutton和一个文本框Inside Repeater的ItemTemplate我想在Linkbutton上获取TextBox的值点击但是我正在调试它时显示为空。



这是代码 -

Textbox Losing its Value after Postback on Repeater_ItemCommand.

there is a Linkbutton and a textbox Inside Repeater's ItemTemplate I want to Get the Value of TextBox on Linkbutton Click but it is Showing Empty when im debugging it.

Here's Code-

protected void Page_Load(object sender, EventArgs e)
   {

       if (!Page.IsPostBack)
       {
           if (Session["MyCart"] != null)
           {
               Cart.DataSource = ((DataTable)(Session["MyCart"])).DefaultView;
               Cart.DataBind();
               Cart.Items[0].Visible = false;
           }
           else
           {
               Response.Redirect("Products.aspx");
           }
       }

   }
   protected void Cart_ItemCommand(object source, RepeaterCommandEventArgs e)
   {
       if (e.CommandName == "UpdateCart")
       {
           string Pid = e.CommandArgument.ToString();
           TextBox txtquantity = (TextBox)e.Item.FindControl("txtQuantity");

           DataTable dt = new DataTable();
           dt = (DataTable)(Session["MyCart"]);
           //// Get all DataRows where the name is the name you want.
           IEnumerable<DataRow> rows = dt.Rows.Cast<DataRow>().Where(r => r["Pid"].ToString() == Pid);
           //// Loop through the rows and change the name.
           rows.ToList().ForEach(r => r.SetField("Quantity", int.Parse(txtquantity.Text)));
           Session["MyCart"] = dt;
           Cart.DataSource = ((DataTable)(Session["MyCart"])).DefaultView;
           Cart.DataBind();
           Cart.Items[0].Visible = false;
       }

   }

推荐答案

你绑定你的转发器购物车在Cart_ItemCommand事件中。它导致重新创建项目模板。您可以在itemdatabound事件中将值绑定回Textbox。
You are binding your repeater "cart" in "Cart_ItemCommand" event. It cause to recreate the item template. you can bind value back to Textbox in itemdatabound event.


这篇关于文本框在Repeater_ItemCommand上回发后丢失其值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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