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
Similar Messages:
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
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
Dec 1, 2013
I have a GridView that is populated via a dataset that contain 1 table. I have enabled paging on my GridView.
In my Updating event, I handle the new values and call a store proc to update my database with the new values for the selected row. In order to minimize the call to the DB, instead of getting back a new dataset with the updated values, I simply update the row of the dataset that I have in session with the new values and then I bind back my gridview.
The problem that I have is since I have let's say 5 pages of 10 row... If I update a row on the first page as soon as I click update, the gridview will show the new values. However, if I select page 3 for example, click on update and update the values, once the update is done, the gridview will still be displayed with the old values.
View 4 Replies
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
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
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
Mar 26, 2010
[Code]....
View 2 Replies
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
Feb 1, 2010
I'm creating a GridView in code. I can successfully attach handlers for Editing, and CancelEditing. RowUpdating never runs, however. Instead, if the GridView is in a Panel, the Edit handler is called when Update is clicked (and this is the command name I get back on the Update click, too). If the GridView is not in a panel, then the Cancel handler is called when Update is clicked (again, this is the command name I get back from clicking Update). I've searched high and low for a reason why the RowUpdating event is not getting called, and I can't find one. Does anyone out there haveHere is my code (My actual code is much more involved than this, but for testing purposes, I extracted the following code and stuck it in a new project to isolate my problem):
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
[code]...
View 1 Replies
Jun 12, 2012
Specified argument was out of the range of valid values.Parameter name: index
After adding a check box to gridview when i am updating teh gridview I get above error
cmd.Parameters.Add("@c_name", SqlDbType.VarChar).Value = ((TextBox)Gridview1Rows[0].Cells[1].Controls[0]).Text;
cmd.Parameters.Add("@c_amt", SqlDbType.VarChar).Value = ((TextBox)Gridview1Rows[0].Cells[2].Controls[0]).Text;
cmd.Parameters.Add("@c_type", SqlDbType.VarChar).Value = ((TextBox)Gridview1Rows[0].Cells[3].Controls[0]).Text;
cmd.Parameters.Add("@check", SqlDbType.Bit).Value = ((CheckBox)Gridview1Rows[0].Cells[4].Controls[0]).Checked;
Before to checkbox addition it was wroking fine
View 1 Replies
Jun 12, 2012
bool isChecked = ((CheckBox)Gridview1.Rows[e.RowIndex].Cells[e.RowIndex].Controls[0]).Checked;
if (isChecked)
{ chk = 1; }
else
{ chk = 0; }
cmd.Parameters.Add("@check", SqlDbType.Int).Value = chk;
in the above code if i unslect the check box i get ischecked value=false & chk value=0 but on updating in sql tbl the value does not chnage.
View 1 Replies
Jan 25, 2011
I have a user requirement to hav the ability to directly edit the gridview without having to click the edit link. I was thinking of showing dropdown lists for each column-to-row so that the user can select the values for each record. Then the table will be updated accordingly (no update link).
Is this possible or do I still need the edit template and specify the item template with the dropdown list?
View 1 Replies
Jun 16, 2015
i ask what code can generate on how to Populate and save ASP.Net Dropdownlist with Selected Value in Gridview Rowupdating ?
View 1 Replies
Aug 18, 2010
How do I change these hyperlinks to say something other then Edit and Cancel?
View 4 Replies
Nov 12, 2011
When I click the Edit button in Gridview twice it'll always show the edit box or (textbox in gridview are editable)how to prevent that?
View 4 Replies
Nov 29, 2010
I am using a gridview to display data and want to implement Edit, Update and Cancel in the GridView. Edit and Cancel are working fine but on update the Gridview isn't exiting out of the edit mode. I am using the gridview inside an UpdatePanel.
[Code]....
View 9 Replies
Sep 20, 2010
where I have gone wrong? changing from VS2003 DataGrid to VS2010 GridView; still on SQL Server 2000 so the wizards for autogenerating the code are not compatible.
Delete works, RowUpdating does not. I get an ArgumentOutOfRangeException on "rowToUpdate("QuoteDQty")
= Me.dgQuoteList.Rows(e.NewValues.Item(1).ToString)"
Private
Sub dgQuoteList_RowUpdating(ByVal sender
As Object,
ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
Handles dgQuoteList.RowUpdating
[code]...
View 2 Replies
Jun 29, 2010
Is there a way to update a value in a gridview, by pressing a button that shows within the cell? For example, i have a really simple gridview showing supply levels, I havr the following SQL table:
ID = Int
PartNumber = varchar
Quantity = Int
I would like to be able to press a "Plus" or "Minus" button on the gridview next to the Quantity (in stock) value which updates the database and re binds the data to the gridview, but without going into edit mode.
View 9 Replies
Jun 21, 2010
I have a gridview and detailview in an updatepanel. My detailview is setup to display the details of a record that is selected in the gridview. When I edit the values in the detailview and click update it does not update the gridview. If I check my database the values have been changed it just haven't been updated in my gridview. Below is my code for the two objects and their datasources.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="RCR_DSM" AllowSorting="True"
DataKeyNames="PartNumber" AutoGenerateSelectButton="True">
<Columns>
[Code]....
View 2 Replies
Jul 10, 2013
I have a gridview that has 3 dropdowns. And when I am in edit mode, when updating via the RowUpdating event, I am not getting a value from my 2nd or 3rd drop downlists. Here's the code from RowUpdating:
Code:
Protected Sub gridOutdoor_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
'WHEN DEBBUGING, the text for ddBodyColor.Text is an empty string. I had selected a value prior to this event firing."
Dim ddBodyColor As DropDownList = DirectCast(gridOutdoor.Rows(e.RowIndex).FindControl("ddBodyColor"), DropDownList)
End Sub
Here's the source code for ddBodyColor:
Code:
<EditItemTemplate>
<asp:DropDownList ID="ddBodyColor" runat="server" TabIndex="2" AppendDataBoundItems="true" Enabled="true" DataTextField="bodyColor" DataValueField="bodyColor"><asp:ListItem Text="Select" Value="" /></asp:DropDownList>
</EditItemTemplate>
View 9 Replies
Aug 3, 2010
My Gridview is refreshing its datasource when the edit button is clicked. How can I prevent this from happening? This isn't much of a problem when there aren't a lot of records, but when there are many it takes awhile. The data is already loaded so the edit button shouldn't need to reload the data. The edit button is a template edit button, and I'm using an SQL Datasource that connects to an Oracle database. The SQL datasource uses a control parameter that points to a dropdownlist.
View 1 Replies
Feb 19, 2010
I am trying to create a basic gridview which has the basic edit and delete capabilities on a webpage using the MVC framework.I have bound the gridview to a LINQ Data source and I can retrieve all my records with no problem. However, when I click on the EDIT link, nothing happens at all. I have assigned my DataKey and viewing all the videos and tutorials on creating a gridview, this was how it is to get a gridview working.Steps taking:1) Created LINQ datacontext2) Created Controller 3) Created Index view4) Drag-and-dropped Gridview control onto Index view and link it to LINQ.5) Enabled CRUD functions on LINQ Datasource and Enabled Editing on Gridview.Can someone please tell me what is wrong or missing? I have tried different ways of getting this to work for 3 days now and I am at my wits end.
View 2 Replies
Jan 19, 2011
This should be easy enough but I can't seem to get it to work. I have a master list table someone forwarded me a separate email table. So, I wrote a quick and very inefficient block to add the emails to the master list. Everything works fine on the form as datagridview1 shows my changes and states the numbers of rows affected. When I check the actual mdb file though, no changes are ever made.
[Code]....
View 2 Replies
Jul 31, 2011
I have a DataView that is bound to a DataSource, which gets its data from a SQL database.I'm converting a desktop app to a web app and I've been able to duplicate the data query side, but I'm having a hard time inserting a new record via the data source. In the desktop app, I don't use a data source. I have a class I created that inserts a new record, but the upkeep is extremely time consuming, so I'm switching to the datasource.When I assign the datasource, I selected the SQL statement/stored procedure option and created my INSERT command via the Query Builder.
The problem I'm running into is that I don't want a SELECT statement. I just want a plain GridView so I can select Edit, fill in the data and then call InsertParameters.If I don't add a SELECT statement, it won't let me finish the wizard and an invalid one throws an exception. The only other thing I could think of, was to call SELECT and set a WHERE based on a column whose value is null. The app runs, but the GridView doesn't appear. How I can only do an INSERT?
View 5 Replies