Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
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
//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">
<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>
You have deleted all records.

Post Your Reply Post New Question

 Viewer's Reply
This Question has 0 replies.

Sponsored by
Backup and Recovery Best Practices for Microsoft SQL Server 2005
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks - Free 158 Page Preview
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview