如何綁定到文本框並在按鈕單擊時檢索修改後的值。將文本框綁定到值
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Sku objSku = new Sku();
objSku.Name = "Test";
Sku = objSku;
frm.DataSource = Sku;
frm.DataBind();
}
if (IsPostBack)
{
Sku = ViewState["Sku"] as Sku;
}
}
public Sku Sku { get; set; }
protected void Button1_Click(object sender, EventArgs e)
{
//Hers sku.Name should be equal to the value entered by the user . so that I can save the object.
}
}
[Serializable]
public class Sku
{
public string Name { get; set; }
}
HTML代碼
<form id="form1" runat="server">
<div>
<asp:FormView runat="server" ID="frm" >
<ItemTemplate>
</ItemTemplate>
</asp:FormView>
<asp:TextBox ID="TextBox1" Text='<%# Bind("Name") %>' runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
但我想我的SKU對象與文本框的值被更新(它應該自動通知SKU對象,有沒有我與設置在點擊按鈕明確地反對價值的事情。這是可能的。(注一沒有將這些控件放在窗體視圖中,它們不在其中。) – user476566 2011-01-26 16:55:07