DataSource Controls :: Gridview Updating The Old Values On RowUpdating?

May 11, 2010

I have a gridview that I'm trying to update the Date something is corrected in the database. When I am putting a new value in, it is updating, but it isn't updating the new value, just the old one that is already there. I cannot figure out why this is happening.

[Code]....

View 8 Replies


Similar Messages:

Forms Data Controls :: Updating Field Value In Gridview Rowupdating Event

Mar 15, 2010

I have a Modified Date and Modified By column in my gridview and I want them to be updated with the current date and current user any time a user updates the row.

I converted my columns to template fields and the textboxes in the edititemtemplate are bound to my sql data columns "ModifiedDate" and "ModifiedBy"

Then I added the attached code in my RowUpdating event.

When I test the code and click the Update link on my gridview I don't get an error but the values don't update either. I put a breakpoint on the code and when I hover over "ModifiedDateLabel.Text" I see the old value of the field so I know I'm accessing the control correctly.

View 3 Replies

Forms Data Controls :: Gridview Rowupdating Contains Old Values

Jul 13, 2010

Here is the code with the issue:

[Code]....

The value of txtName, for example, contains the value prior to editing and clicking update. Here is the grid code:

[Code]....

View 17 Replies

Forms Data Controls :: GridView RowUpdating - Unable To Get New Values

Apr 23, 2010

I have a GridView on my page and I have bound a custom DataSource (DataTable populated from an SQL query) within an UpdatePanel. I have set the OnRowUpdating property and create the code behind stuff as well as setting AutoGenerateEditButton to true. The problem I have is that when I click on 'Edit', then change some values then click 'Update', I can only get the old values.

.ASPX

[Code]....

All of the other posts I have read have mentioned the GridView being bound on post back or within a RowDataBound event but I'm pretty sure that I am not doing that.The RowUpdating event does fire but the value of Jockey, for example, is still the original.

View 3 Replies

Forms Data Controls :: GridView Rowupdating Returns Old Values?

Sep 24, 2010

my gridview row updating events return old values.. edititem templatefield gets its old value on row updation.

My code is as follows :-

[Code]....

View 5 Replies

VS 2010 / Updating A Row In A Gridview Using EDIT Link (RowUpdating Event)

Nov 27, 2013

I have a gridView that is populated with a dataset from an Oracle Database.

When I click on the EDIT button, it will redisplay my gridView with textboxes so I may make some changes.

Let's say one row is currently:

OPEN_TIME = 1 CLOSE_TIME = 2

When I click EDIT, 1 and 2 are in a textbox. If I change both values to 5 and click UPDATE, it will fire a RowUpdating..

Here is the code from my APP:

Private Sub gvBusinessHours_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvBusinessHours.RowUpdating
Dim strOpenTime As String = DirectCast(gvBusinessHours.Rows(e.RowIndex).FindControl("txtOpenTime"), TextBox).Text
Dim strCloseTime As String = DirectCast(gvBusinessHours.Rows(e.RowIndex).FindControl("txtCloseTime"), TextBox).Text
End Sub

The problem is the values I am getting are the OLD ones and not the new ones... I am getting 1 and 2 and not 5 AND 5...

what I am doing wrong ?

View 5 Replies

Get Old Gridview Row Values In The RowUpdating Event

Aug 25, 2010

How do I get the old values in a gridview row in the row_updating event? I'm using a sqldatasource control to populate the grid and want to write the update code in the RowUpdating event. There are 10 fields displayed in the grid. I can get the value of the first field using string old_Category = e.OldValues[0].ToString();.

But it doesn't work for index items greater than 0. This doesn't work string old_Category = e.OldValues[1].ToString(); it returns an error message Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index. even though there are 10 columns in the grid.

<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
BorderWidth="0px"
BorderStyle="None"
Width="100%"
CellPadding="2"
PageSize="25"
OnRowDeleting="ProjectListGridView_RowDeleting"
onrowdatabound="GridView1_RowDataBound"
onrowupdating="GridView1_RowUpdating" onrowediting="GridView1_RowEditing" >
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="WeekEnding" SortExpression="WeekEnding">
<ItemTemplate>
<asp:Label ID="lblWeekEnding" runat="server" Text='<%# Bind("WeekEnding") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Project" SortExpression="Project">
<EditItemTemplate>
<asp:DropDownList
ID="DropDownList1"
runat="server"
DataSourceID="sdsDdlProjectsEdit"
DataTextField="ProjectName"
DataValueField="ProjectID"
AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"
>
</asp:DropDownList>
<asp:SqlDataSource
ID="sdsDdlProjectsEdit"
runat="server"
ConnectionString="<%$ ConnectionStrings:ttuser %>"
SelectCommand="SELECT ProjectID,ProjectName FROM dbo.aspnet_starterkits_Projects">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Project") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category" SortExpression="Category">
<EditItemTemplate>
<asp:DropDownList
ID="DropDownList2"
runat="server"
DataSourceID="sdsDDL2"
DataTextField="CategoryName"
DataValueField="CategoryID">
</asp:DropDownList>
<asp:SqlDataSource
runat="server"
ID="sdsDDL2"
ConnectionString="<%$ ConnectionStrings:ttuser %>"
SelectCommand="SELECT [CategoryID], [CategoryName],[ProjectID] FROM dbo.aspnet_starterkits_ProjectCategories WHERE ([ProjectID]=@ProjectID)">
<SelectParameters>
<asp:Parameter Name="ProjectID" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Category") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sun" SortExpression="Sun">
<EditItemTemplate>
<asp:TextBox ID="txtSunEdit" runat="server" Text='<%# Eval("Sun") %>' Columns="2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSun" runat="server" Text='<%# Bind("Sun") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mon" SortExpression="Mon">
<EditItemTemplate>
<asp:TextBox ID="txtMonEdit" runat="server" Text='<%# Eval("Mon") %>' Columns="2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Mon") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tue" SortExpression="Tue">
<EditItemTemplate>
<asp:TextBox ID="txtTueEdit" runat="server" Text='<%# Eval("Tue") %>' Columns="2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Tue") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Wed" SortExpression="Wed">
<EditItemTemplate>
<asp:TextBox ID="txtWedEdit" runat="server" Text='<%# Eval("Wed") %>' Columns="2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Wed") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Thu" SortExpression="Thu">
<EditItemTemplate>
<asp:TextBox ID="txtThuEdit" runat="server" Text='<%# Eval("Thu") %>' Columns="2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Thu") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fri" SortExpression="Fri">
<EditItemTemplate>
<asp:TextBox ID="txtFriEdit" runat="server" Text='<%# Eval("Fri") %>' Columns="2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Fri") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sat" SortExpression="Sat">
<EditItemTemplate>
<asp:TextBox ID="txtSatEdit" runat="server" Text='<%# Eval("Sat") %>' Columns="2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Sat") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and here is the sqldatasource
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ttuser %>"
SelectCommand="SELECT
@WeekEnding WeekEnding
,Project
,ProjectID
,Category
,CategoryID
,isnull([1], 0) Sun
,isnull([2], 0) Mon
,isnull([3], 0) Tue
,isnull([4], 0) Wed
,isnull([5], 0) Thu
,isnull([6], 0) Fri
,isnull([7], 0) Sat
from
(select P.ProjectName Project,P.ProjectID, CAT.CategoryName Category,CAT.CategoryID, Datepart(dw, TE.TimeEntryDate) DOW, TE.TimeEntryDuration Hours
FROM
dbo.aspnet_starterkits_TimeEntry TE inner join
dbo.aspnet_starterkits_ProjectCategories CAT on
TE.CategoryID=CAT.CategoryID inner join
dbo.aspnet_starterkits_Projects P on
CAT.ProjectID=P.ProjectID
Where (TE.TimeEntryDate between dateadd(dd, -6, @WeekEnding) and @WeekEnding) AND
TE.TimeEntryUserID=(SELECT UserId FROM dbo.aspnet_Users WHERE UserName=@UserName)) Source
pivot (max(Hours)for DOW in ([1],[2],[3],[4],[5],[6],[7]) ) as pvt" OldValuesParameterFormatString="original_{0}"
<SelectParameters>
<asp:ControlParameter ControlID="WeekEnding2" Name="WeekEnding"
PropertyName="Text" />
<asp:ControlParameter ControlID="UserList" Name="UserName"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

View 1 Replies

Forms Data Controls :: Updating The Datasource / Mark All The Values In The Binding Column Of Datasource If Checkbox In Headertemplate Is Checked?

Sep 29, 2010

Scenario:
I am creating a custom gridview control which has a custom CheckBoxTemplateField column (deriving from TemplateField class). This template field column has custom Checkboxheadertemplate (implementing ITemplate) and CheckboxItemTemplate (also implementing ITemplate). In InstantiateIn method of both templates (header as well as Item template), I am adding a checkbox control which has Autopostback = true.

My requirement is:
I want to mark all the values in the binding column of datasource if checkbox in headertemplate is checked. I dont want to mark only rows visible on grid. I WANT TO MARK ALL ROWS IN DATASOURCE. I want to do this in _CheckedChanged event of checkbox in header template.

Problem I am facing: When I check/uncheck the checkbox in header, it postbacks. so in OnCheckedChanged event, gridview's datasource is null. Secondly, in any event of gridview, I could access only those rows of datasource for which corresponding rows are visible in gridview through Gridviewrow.DataItem property. But I want to set it for all rows in datasource.

View 5 Replies

DataSource Controls :: How To Retain Old Values On Updating With Stored Procedure

May 25, 2010

How to Retain old values on updating with Stored Procedure

View 6 Replies

Data Controls :: Dynamically Change GridView Values Without Updating In Database?

Aug 24, 2013

how to change gridview cell value for a checked row without affecting any changes in database for ex if a row contains quantity of item 6 i want to change it value to 5,4 upto 0 that is on click event of delete quantity button i have identified row with a checkbox in grid view.

View 1 Replies

Forms Data Controls :: When Updating Gridview When Hide Columns Values Turn To Null?

Mar 5, 2010

I am updating a gridview. Problem is that when I hide certain fields that I do not want the user to update, they lose their values ie. the data is wiped out in the field unless I show them on the grid and make them writeable. Is there a property I need to set for the field to retain the value when the grid is updated or is this in the sql statement?

View 7 Replies

DataSource Controls :: Decimal Values Not Updating With Decimal Places?

Apr 6, 2010

I'm trying to execute this statement every minute with SQL Agent, I have it set up as a job:

[Code]....

It's trying to update a column which data type is set to decimal. Just so you know what I really need out of it, here is an example:

[Code]....

The answer of which should add on 0.5 to the original value. If I were to use the increase value of 60 which then becomes 60/60 it will work.I'm dividing by 60 because the increase value is per hour so I make it smaller to get per minute value. Why is it doing this?

View 2 Replies

DataSource Controls :: Updating Database With Gridview Control

Nov 30, 2010

I am sure I am not the first to ask this question but I cannot find an answer in these or any other forums. I guess I am not wording the question right. In short I have a gridview populated but a database via an SQLDatasource. I have an Edit column in the datagrid and an updatequery in the datasource. When the Edit is click the line goes into edit mode, the user then clicks Update and I get an error. Could not find control 'DropDownList1' in ControlParameter 'Frequency'. The only complication is that there is a drop down control when the "EDIT" column is selected. The dropdownlist gets it list from another SQLDatasource. This all works fine. Here is the code snip:

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateEditButton="True"

View 12 Replies

Forms Data Controls :: GridView Updating Having Datasource Datatable?

Jul 16, 2010

I am making shopping cart application.On Viewing Shopping Cart,when i try to update the quatity of product column it permit me to edit but wn i click update link.the gridview disappears wid all products.send me some code snippet in C# as i want only quantity column to be editable.I am using the following code:in Code behind File

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;

[code]...

View 4 Replies

Forms Data Controls :: GridView - RowUpdating Not Firing

Apr 1, 2010

I've put a simple gridview on my Asp.net webpage. I've configured the fields via C# code:

gvMainDataGrid.AutoGenerateColumns = false;
gvMainDataGrid.AutoGenerateDeleteButton = false;
BoundField bfldSeqNmbr = new BoundField();
bfldSeqNmbr.DataField = "PKSequenceNmbr";
bfldSeqNmbr.Visible = false;
gvMainDataGrid.Columns.Add(bfldSeqNmbr);
BoundField bfldEmployeeCode = new BoundField();
bfldEmployeeCode.DataField = "Employee Code";
bfldEmployeeCode.HeaderText = "Employee Code";
gvMainDataGrid.Columns.Add(bfldEmployeeCode);
BoundField bfldProjectCode = new BoundField();
bfldProjectCode.DataField = "Project Code";
bfldProjectCode.HeaderText = "Project Code";
gvMainDataGrid.Columns.Add(bfldProjectCode);
BoundField bfldProcessCode = new BoundField();
bfldProcessCode.DataField = "Process Code";
bfldProcessCode.HeaderText = "Process Code";
gvMainDataGrid.Columns.Add(bfldProcessCode);
BoundField bfldActivityDate = new BoundField();
bfldActivityDate.DataField = "Date";
bfldActivityDate.HeaderText = "Date";
gvMainDataGrid.Columns.Add(bfldActivityDate);
BoundField bfldActivityHours = new BoundField();
bfldActivityHours.DataField = "Activity Hours";
bfldActivityHours.HeaderText = "Activity Hours";
gvMainDataGrid.Columns.Add(bfldActivityHours);
CommandField cfldDeleteButton = new CommandField();
cfldDeleteButton.ShowDeleteButton = true;
gvMainDataGrid.Columns.Add(cfldDeleteButton);
It's data source is a Dataset retrieved from a webservice. Here is the C#code to bind the data to the gridview
Service1 MyService = new Service1();
dsMainData = MyService.GetData(strIdNumber);
gvMainDataGrid.DataSource = dsMainData;
gvMainDataGrid.DataBind();

It retrieves great. No problems at all. Then, when I actually try to use the delete button, I get an error that the RowDeleting event is not being handled. I thought that was pretty explicit, so I created the event:

private void gvMainDataGrid_RowDeleting(Object sender, GridViewDeletedEventArgs e)
{
return;
}

Well.....that didn't work. So, I thought that maybe I needed to configure it via the actual aspx file. So, I changed

<asp:GridView ID="gvMainDataGrid" runat="server">
</asp:GridView>
to this:
<asp:GridView ID="gvMainDataGrid" runat="server" ondeleting="gvMainDataGrid_RowDeleting">
</asp:GridView>

But, no avail. I've scoured the web and tried so many combinations of capital letters and whatnot -- but no effect.

View 3 Replies

C# - Cells In Gridview Lose Controls On RowUpdating Event?

Jan 6, 2010

I'm using a GridView to display some columns and rows that reside in a database. This works excellent. Because i wanted to add columns dynamically out of a List of names. Let's say we have a list with 5 names in it, then it dynamically creates a column for every name in the GridView.

Here's some code to display what i do:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Create columns for each student
List<Student> allStudents = new Eetlijst.Business.Students().GetAll();
allStudents.Reverse();.......

How do i create the dynamic columns for each row? I create them with a DataBound event. So when the GridView databinds, the columns get filled with data. There is also a check inside to see if the row is in edit mode or not. So when i click on the edit button next to the row, the row goes perfectly in edit mode. The code i made adds a TextBox control to the cell.

When i fill in a value and press the Update button, it can't find any controls anymore and therefore i can't get the value i entered. The control is still there in the DataBound when i put a break point after it. But as soon as i click the Update button, all the controls of the cells are gone.

I searched on the internet and all i found is that it has something to do with the application firing a postback before it reaches the RowUpdating method.

So, how can i let the controls exist that i added to the cell when it is in edit mode?

View 2 Replies

Forms Data Controls :: E.values Updating Values But Not After Manipulating The String?

Nov 19, 2010

I am using Asp.net 3.5 listview control. In item_updating event I am using this code...

dim country as string = Dim country As String = e.NewValues("country_name").ToString.Replace(" ", "")

It's updating record correctly. for example if I update USA to USA 1 1 then it's updating like as it. But I want it to be USA11

View 2 Replies

Forms Data Controls :: Dynamic Gridview Is Empty On RowUpdating?

Mar 18, 2010

[Code]....

Dynamic Gridview is Empty on RowUpdating

View 9 Replies

Forms Data Controls :: Use Nested Gridview's Rowupdating Event?

Aug 31, 2010

I have a GridView within a GridView. I want o access child gridview's rowupdating event. i want to update row.

this is my GridView's code as follows

[Code]....

View 6 Replies

Forms Data Controls :: GridView Event RowUpdating / RowUpdated?

Mar 26, 2010

[Code]....

View 2 Replies

Forms Data Controls :: ENewValues Not Working With RowUpdating On GridView?

Nov 25, 2010

I have a GridView ona "View Order" page which pulls data from a table: an item name, its description, the quantity ordered, the unit price and the total (item) cost: unit price * quantity ordered. This data, including the calculation for total cost is handled on the previous "Place Order" page using a Stored Procedure.

I want the user on the "View Order" page to be able to hit the standard "Edit" link (Command Field over at the left) and then change the "Quantity" field. This works fine and, when "Update" is hit, the field reflects the change.

PROBLEM: Because the Total Cost is calculated on the previous page, thsi doesn't change, I need to calculate it again.

WHAT I'VE TRIED: I've stripped the TotalCost field out of the SqlDataSource Update commands and attempted to use e.NewValues in the RowUpdating event handler to inject the new calculation. This doesn't work.

WHAT HAPPENS: The "ViewOrder" page refreshes, the new quantity is there but the TotalCost has not changed. No errors reported.

Is this the right way to do it and, if so, is my code okay? Here it is:

ASPX for ViewOrder:

[Code]....

And here's the Code Behind for ViewOrder:

[Code]....

"OrderMealValue" is the field for the Total Cost.

The fourth colum contains the Quantity and the fifth the price for one item.

View 2 Replies

Forms Data Controls :: DropDownList Disappears From Gridview On RowUpdating?

Jan 21, 2011

I am populating a column in a gridview with a dropdownlist as follows:

[Code]....
[Code]....

When I edit the gridrow, the dropdown is there and I can select a new item.

But I can't find the dropdown during the rowupdated event. The cell control says it's a Textbox. All of the other items in the row are fine and I can get the data back. But I can't get the DropDown item.

Here are some of the things I have tried in the RowUpdating event:

DropDownList test = (DropDownList)e.FindControl("ddlPeriod");
//null
DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlPeriod");
//Also null
var test = row.Cells[8].Controls[0];
//Says its a textbox.

View 5 Replies

Forms Data Controls :: E.Cancel In GridView:RowUpdating() Does Not Work?

Mar 3, 2010

I have a GridView. I allow editing using:

[Code]....

As I allow editing of row, so I have GridView:RowUpdating(). In it, I check if the entered value is valid. If not, I have e.Cancel = true.

[Code]....

After I see the message box comes up, the textbox still stays the same. I expect the textbox will disappear just as if I have pressed the Cancel button. (By the way, the ClientUtil is a class someone has written for me.)

How do I make the e.Cancel = true works as if I press the Cancel button.

View 2 Replies

Forms Data Controls :: Unable To Update Row Using Gridview Rowupdating Event

Jun 17, 2010

I am trying to update the row using gridview_rowupdating event but I am unable to update. I tried the code like this...

foreach (GridViewRow i in GridView1.Rows)
{
TextBox sname = i.FindControl("sname") as TextBox;
TextBox fname = i.FindControl("fname") as TextBox;
TextBox sex = i.FindControl("txtsex") as TextBox;
// Label lblpin1 = i.FindControl("lblpin") as Label;
TextBox tpin = i.FindControl("txtpin") as TextBox;
tpin.Enabled = true;
// lblpin1.Enabled = true;
string pinno;
pinno = Convert.ToString(tpin.Text.Trim());
conn2.Open();
SqlCommand cmd = new SqlCommand("update NRDetails2010 set SNAME='" + sname + "',FNAME='" + fname + "',SEX='" + sex + "' where pin='" + pinno.Trim() + "' and InstCode='" + Session["UId"] + "' and Sem='" + ddlsem.SelectedItem.Text + "' and scheme='"
+ ddlscheme.SelectedItem.Text.Trim() + "' ", conn2);
cmd.ExecuteNonQuery();
conn2.Close();
}

I am getting error at cmd.ExecuteNonQuery()

Here I am giving connection globally and opening in this event. In gridview, I am updating 3 fields depending on 4 conditions.

View 3 Replies

Forms Data Controls :: Gridview Rowupdating Throws Index Out Of Range

Dec 17, 2010

The table serving as the data source is a simple access table.

[Code]....

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved