2015-12-14 74 views
1

中的gridview值,同時更新gridview記錄。舊值只會更新。即時使用綁定字段。在獲取變量中的數據時獲得舊值。背後無法更新.net

protected void GvLeads_RowUpdating(object sender, GridViewUpdateEventArgs e) 
{ 

    GridViewRow row = GvLeads.Rows[e.RowIndex]; 
    String str = ((TextBox)(row.Cells[1].Controls[0])).Text; 
    int Leadid = Convert.ToInt32(str); 
    string CompanyName = ((TextBox)(row.Cells[2].Controls[0])).Text; 
} 

回答

1

<asp:GridView runat="server" ID="GvLeads" AutoGenerateColumns="false" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" OnRowDeleting="GvLeads_RowDeleting" OnRowEditing="GvLeads_RowEditing" OnRowCancelingEdit="GvLeads_RowCancelingEdit" EmptyDataText="No Records Found" OnRowUpdating="GvLeads_RowUpdating" OnRowDeleted="GvLeads_RowDeleted"> 
<Columns> 
    <asp:BoundField HeaderText="Id" DataField="LeadId" /> 
    <asp:BoundField HeaderText="Company" DataField="Companyname" /> 
</Columns> 
</GridView > 

代碼,當你在Page_Load只要在這之前Page_Load事件得到的所謂其填充與初始值電網RowUpdating事件被稱爲網格填充通常發生。如何避免?使用!IsPostBack爲此目的

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     BindGrid(); // For e.g. 
    } 
} 
+0

謝謝...你幫我 –

+0

歡迎,快樂幫助你。 – Prabhat