ASP.NET - Textbox comes in boundfield after clicking save button outside grid

Asked By anbu n on 25-Apr-13 01:06 AM
<asp:GridView ID="gvFinancialdtls" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="Financial_Year_Id" EmptyDataText="Financial year is empty" EmptyDataRowStyle-HorizontalAlign="Center"
OnPageIndexChanging="gvFinancialdtls_PageIndexChanging" OnRowDeleting="gvFinancialdtls_RowDeleting"
OnRowEditing="gvFinancialdtls_RowEditing" OnSorting="gvFinancialdtls_Sorting"
Width="60%" OnDataBound="gvFinancialdtls_DataBound">
<Columns>
<asp:BoundField DataField="From_Date" HeaderStyle-Width="30%" HeaderText="From Date"
ItemStyle-Width="20%" SortExpression="From_Date" />
<asp:BoundField DataField="To_Date" HeaderStyle-Width="20%" HeaderText="To Date"
ItemStyle-Width="20%" SortExpression="To_Date" />
<asp:BoundField DataField="Notes" HeaderStyle-Width="20%" HeaderText="Notes" ItemStyle-Width="60%"
ControlStyle-Width="20%" />
<asp:CommandField ShowEditButton="True" ButtonType="Link" ControlStyle-CssClass="gvEdit"
EditText="<div>Edit</div>" />
<asp:CommandField ShowDeleteButton="True" ButtonType="Link" ControlStyle-CssClass="gvDelete"
DeleteText="<div>Delete</div>" />
</Columns>
</asp:GridView>
---------
code behind - Row editing

private void BindFinancialeditdtls(int index)
{
string notes;
LblFinancial_Year_Id.Text = gvFinancialdtls.DataKeys[index].Value.ToString();
string fromdate = gvFinancialdtls.Rows[index].Cells[0].Text;
string todate = gvFinancialdtls.Rows[index].Cells[1].Text;
if (gvFinancialdtls.Rows[index].Cells[2].Text.Length > 30)
{
notes = gvFinancialdtls.Rows[index].ToolTip;


}
else
{
notes = gvFinancialdtls.Rows[index].Cells[2].Text;
}


txtCalfromdate.Text = fromdate;
txtCaltodate.Text = todate;
txtRemark.Text = notes;
}



protected void gvFinancialdtls_RowEditing(object sender, GridViewEditEventArgs e)
{ BindFinancialeditdtls(e.NewEditIndex);
}

after editing , values applies to above textbox, but after saving the edited value by clicking Save Button outside grid. The edited row displays textbox instead of bound field, also new button named update & cancel are rendered.


how to avoid the textbox rendering in boundfield & update & cancel button in the edited row.

Thanks
anbu n replied to anbu n on 26-Apr-13 06:46 AM
In save button click event add line

 
gvFinancialdtls.EditIndex = -1; //Turn the Grid to read only mode

      BindGridView(); // Rebind GridView to reflect changes made