AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Problem in Editing Gridview
Posted by Ramani Sandeep on  11/8/2008 1:25:01 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
when i edit gridview it shows textbox ..but when i press update button it does not work for me.. it do not show any error as well as not updating values.. it show me only edit mode .. but when i cancel update mode .. it wil go back to normal mode.. so help me out abt this..

here is my code:

protected void gvMaterialDetail_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView GridView1 = (GridView)sender;
GridView1.EditIndex = e.NewEditIndex;
BindGrid(GridView1, Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex][0].ToString()));
}

protected void gvMaterialDetail_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView GridView1 = (GridView)sender;
GridView1.EditIndex = -1;
BindGrid(GridView1, Convert.ToInt32(GridView1.DataKeys[e.RowIndex][0].ToString()));
}

protected void gvMaterialDetail_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

GridView GridView1 = (GridView)sender;
TextBox txtPrice = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];

//Update Price into DataBase Table
double Price = Convert.ToDouble(txtPrice.Text);
int MaterialDetailID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex][1].ToString());

bool rv = BAL_MaterialDetails.Update(MaterialDetailID, Price);

if (rv == true)
{
//Successfully Updated
}
else
{
//Error in Update
}

GridView1.EditIndex = -1;
BindGrid(GridView1, Convert.ToInt32(GridView1.DataKeys[e.RowIndex][0].ToString()));

}

<asp:GridView ID="gvMaterialDetail" runat="server" AutoGenerateColumns="False" DataKeyNames="MaterialTypeID,MaterialDetailID"
GridLines="Horizontal" Width="100%" CssClass="gridview" OnRowDataBound="gvMaterialDetail_RowDataBound"
OnRowEditing="gvMaterialDetail_RowEditing" OnRowCancelingEdit="gvMaterialDetail_RowCancelingEdit"
OnRowDeleting="gvMaterialDetail_RowDeleting" OnRowUpdating="gvMaterialDetail_RowUpdating">
<Columns>
<asp:BoundField DataField="BrandName" HeaderText="Brand Name"></asp:BoundField>
<asp:BoundField DataField="Price" HeaderText="Price"></asp:BoundField>
<asp:BoundField DataField="Unit" HeaderText="Unit"></asp:BoundField>
<asp:BoundField DataField="LastUpdated" HeaderText="LastUpdated"></asp:BoundField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True"></asp:CommandField>
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True"></asp:CommandField>
</Columns>
<EmptyDataTemplate>
You have deleted all records.
</EmptyDataTemplate>
</asp:GridView>

Post Your Reply Post New Question

 Viewer's Reply
This Question has 0 replies.

 
Sponsored by
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter
When Good HTML Goes Bad: How You Can Protect Your Web Applications
Introduction to Software Development