Click here to Skip to main content
12,253,371 members (51,266 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET Gridview
Dear Friends, I'm facing problem in a very basic area of gridview. I'm using a Gridview to display records and then have Edit option for each row. I'm not using any control inside gridview, directly values are there.

Now, when user clicks update button in edit mode, not getting updated value from any columns of gridview. Gridview structure is like:
<asp:GridView ID="gvTime" runat="server" AutoGenerateEditButton="True" 
                    AutoGenerateColumns="True" CellPadding="1" CellSpacing="1" 
                    onrowcancelingedit="gvTime_RowCancelingEdit" onrowediting="gvTime_RowEditing" 
                    onrowupdating="gvTime_RowUpdating">
                    <RowStyle HorizontalAlign="Center" />
                    <HeaderStyle HorizontalAlign="Center" />
                    <EditRowStyle BackColor="#CCFFCC" ForeColor="Maroon" HorizontalAlign="Center" />
                </asp:GridView>
Now, in Rowupdating event, it's like :
<pre lang="c#">
 protected void gvTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
int index = int.Parse(Session["Index"].ToString())+1;
GridViewRow row = gvTime.Rows[index];
string overtime = e.NewValues[0].ToString();
gvTime.EditIndex = -1;
BindData();

Here string overtime is always showing olddata, never can pull new data entered by user. I want to manually call SQLCommand to update database based on this updated value from the above function. Please give me some solution.
Posted 27-Aug-12 4:52am
Edited 27-Aug-12 4:56am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

 protected void gvTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
int index = e.RowIndex;
GridViewRow row = gvTime.Rows[index];
//Call your update statement here!
UpdateData(ID); //Something like this
BindData();

Hope it helps.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Dear Christian, thanks for your prompt reply. I tried this one, but whenever I'm trying to update with updated columns, all values are coming as old existing values. So what to do?
  Permalink  
Comments
KARTHIK Bangalore 21-Apr-16 11:37am
   
.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 27 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100