ADO.NET :: Row Updating In A Gridview?
Feb 23, 2011I am updating values in a gridview below is my code [Code]....
but whenever i update the value it is not getting updated in the database and it is not showing any error.
I am updating values in a gridview below is my code [Code]....
but whenever i update the value it is not getting updated in the database and it is not showing any error.
I have a parent gridview which has a child gridview in the itemsTemplate. Both are binded to different SqlDataSources. I can successfully update and delete rows in the child gridview. After updating in the child gridview, some related data in the parent gridview are not updated automatically. So i have placed ParentGridview.Databind() in the rowupdated event of child gridview. But it doesnt look working.
How can i accomplish this?
[Code]....
[Code]....
I have a GridView with 5 fields. Only two of the fields are edittable (the others are READONLY).
I have an UpdateCommand as follows
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NHLPOOL %>"
SelectCommand="SELECT [PlayerID], [Firstname], [lastname], [Goals], [Assists], [Goals]+[Assists] as Points, [AsOfDate] FROM [PlayerStats], [Player] where [PlayerStats].[PlayerID] =[Player].[ID] ORDER BY Points DESC"
UpdateCommand="UPDATE PlayerStats SET Goals =@GOALS, Assists =@ASSISTS, AsofDate=GETDATE() WHERE PLAYERID = @PLAYERID">
</asp:SqlDataSource>
The issue is I want the PLAYERID GV column to be READONLY but I get a runtime error when updating if the PLAYERID is READONLY.
I get the error "
Must declare the scalar variable "@PLAYERID"."
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.
I have a Gridview with these parameters:
<asp:GridView runat="server" ID="ItemGrid" CssClass="Grid"
AutoGenerateColumns="false"
AutoGenerateDeleteButton="true" OnRowDeleting="RowDeleting"
AutoGenerateEditButton="true" onRowEditing="RowEdit"
OnRowCancelingEdit="CancelRowEdit" onRowUpdating="RowUpdating"
DataKeyNames="Item_ID">
<Columns>
<asp:BoundField HeaderText="Item" DataField="Item"/>
<asp:BoundField HeaderText="Family" DataField="Family"/>
<asp:BoundField HeaderText="Structure" DataField="Structure"/>
<asp:BoundField HeaderText="Updated" ReadOnly="true" DataFormatString="{0:d}" DataField="Updated"/>
</Columns>
</asp:GridView>
On updating it calls:
protected void RowUpdating(object sender, GridViewUpdateEventArgs e){
int Item_ID = (int)this.ItemGrid.DataKeys[e.RowIndex][0];[code]...
It generates the Update/Edit/Delete buttons, my Delete function is working exactly how I want and the 'Edit' button generates editable TextBoxes as it should.
My problem is in the updating part, the strings Item, Family, Structure are getting the old values, not the new values I put in the generated text boxes.If I hard code in values they are updated to the database and the DateTime.Now is always updating correctly in the database so the update query is working.
I've been looking at this/reading forums testing things for a couple days now. I'm sure I'm just missing something simple that I have overlooked.
Edit:It has been answered but for those who were curious this is my dataBind();
protected void dataBind()
{
ItemTableAdapter taItem = new ItemTableAdapter();
this.ItemGrid.DataSource = taItem.GetActive();
this.ItemGrid.DataBind();
}
I have a GridView with ItemTemplate and EditTemplate. There is some text boxes in EditTemplate. I want to update records myself using EditTemplate controls. Which event of GridView I should use? If I use Telerik's RadGrid then what event is better?
View 1 RepliesI'm facing the following issue:
I have a gridview that allows updating. I only want to show the relevant fields to the user. As a result I hide the ID field of the records. But I need this value as a parameter for my update command. Apparently the value is always passed as 0 when the field is set invisible. When the field is set visible, the right value is passed.
I know it is possible to refer to a selected row and its controls, to get their values, even for invisible fields. This is what I want to do when the row is updating, in order to get the ID value of the label control which holds the ID value. How do I refer to the row that is updating? I experienced that the row is not considered 'selected', so the SelectedRow property of the gridview does not do the trick.
I have a grid view and have five dropdownlist on it. I have edit update and cancel edit buttons on each row.
Drop down list is updating the database, but only first value in the dropdownlist even when user select second, third or any other value from the dropdownlist.
What could possible be the reason for this. Here is my row Edit/ CancelEdit and Updating Events.
[code]....
Im using a LINQDataSource to populate a GridView of Universities.
Each University has an associated State, which is in another table and associated by a foreign key (StateID).
I have a TemplateField in the GridView so that when you view it normally it displays the StateName which comes from the State table and when you edit it shows a DDL populated with everything from the State table.
[Code]....
If I debug, inside of RowUpdating, GridViewUpdateEventArgs.NewValues doesnt even have a key for State.
Question: How do I let my gridview know I want it to update this column? All the BoundFields just seem to work...
I am working on a page to let a user import an excel file into our database. I want to allow the user to manipulate certain fields before committing the information so I loaded a DataSet from the Excel file and bound that to a GridView. For some reason on rowUpdate my NewValues collection is empty. Here is my GridView:
<cc1:WWGridView ID="gvImportDisplay" runat="server" CssClass="grid-view" AllowSorting="false" ShowHeader="true"
AutoGenerateColumns="true"
AutoGenerateEditButton="true"
OnRowEditing="gvImportDisplay_RowEditing"
OnRowCancelingEdit="gvImportDisplay_RowCancelingEdit"
OnRowUpdating="gvImportDisplay_RowUpdating"
>
<EmptyDataTemplate>0 results found. </EmptyDataTemplate>
</cc1:WWGridView>..............................
I have a GridView which needs to get updated on RowUpdating Event. How can I update data using LINQ?
I am populating GV using LINQ too and here is the code for that:
protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryString["EntityID"];
int getIntEntity = Int16.Parse(getEntity);
using (OISLinq2SqlVs1DataContext dt = new OISLinq2SqlVs1DataContext())
[Code]....
Which is the correct event to handle Updating of a row in my gridview. The gridview is bound to an objectdatasource. I added a tamplate field like this to handle editing a row:
Code:
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"> </asp:LinkButton>
</ItemTemplate>
[Code] ....
No I need to handle the Update Button click.I need to set the ObjectDatasources Update params and call the update method. I'm not sure which is the correct event to do this. IS it gridview_RowUpdating??
I was wondering if when you add the update link for gridview records, is there a way to only allow the user to update just one field in the record?
View 1 RepliesI have 2 gridviews in an update panel that for some reason will not update. There is no data entry, paging, sorting going on, the data is just there to be displayed. I'm using a timer that initiates every 5 minutes to trigger the updatepanel. I also have an updatepanel on an additional page where I am also using a trigger to fire the updatepanel with 2 charts and 1 oneline/column gridview. The 2 charts update just like they are supposed to however the gridview does not. Here is the code for the 2 Gridview aspx page:
[Code]....
Does anyone know the solution to this issue or if Gridviews just don't refresh in UpdatePanels.
I have a very simple application that works almost all the time. I am using an UpdatePanel. My script manager is configured to enable partial rendering. My UpdatePanel is configured for conditional update mode. My asynchronous trigger is a timer that runs every 3 seconds. I track unhandled exceptions in the database. I am not getting any unhandled exceptions. Nor am I getting managed exceptions. Now, I had two users side by side running the application today. I had one record in the data queue. The first user did not get updates; her grid did not update. The second user did get updates. The only difference was that the first user was logged in for a long period of time. The second user logged in just before the test. I reviewed the IIS log file and both users were polling the page every 3 seconds for the same data. So why didn't the first user's grid update? The code follows.
<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="30" EnablePartialRendering="true"></asp:ScriptManager>
[Code]....
In my code behind I have the following timer logic. [Code]....
I am doing the school project and trying to implement updating through gridview but somehow dones't work at all.
[Code]....
I am using LINQ to SQL and on my DetailsView it updates fine but with my gridview it is not. Both I used template fields so I am not sure what the issue is?
[Code]....
[Code]....
[Code]....
I have been doing a lot of reading and searching and I cannot figure out why this is not working for me.
I have to use SQLDataSource for inserting, updating and deleting in database through gridview instead of using SqlDataAdapter and SqlCommand object. I have to do it in ADO.NET (means C# code).
View 3 RepliesI was able to get the code below to give me the value I want from my SQL table however it has to display it in a gridview so I assume that something in the code acutally makes the result a data source rather than a string value.
[Code]....
First off I'm using VS 2008 C# (3.5 Framework) and Linq2Sql for ORM. I have a gridview that represents a SQL database table. I want a users to be able to double-click the rows and get the edit items then be able to edit them and move on without them committing the changes to the database until the user clicks the save button. I know how to make the gridview work and all, my issue is that currently I'm having to keep session objects for the table data and edit them as opposed to a Linq2SQL datasource (because that seems to always automatically commit the change to the database). Also, I'm having trouble getting the changes in the edit controls to reflect in my session data objects. Does anyone have any great working examples of doing this type of work in a gridview. I know there are a lot, but I don't see any with Linq2SQL and not committing changes to the database immediately. Sorry I'm usually a back system developer, so I'm not a UI guru.
View 1 Replies I am trying to set up a GridViewUpdate, I need to find the Parameter and I am having trouble figuring it out.
How would I go about obtaining the value for "@ID" parameter in order for the user to update the required "TAUpdateDate" field?
[Code]....
I have a datagrid that is displaying data that is being returned from a stored procedure. That works fine. The problem is that I want to do sorting. I know that there is sorting functionality in the grid, however, I don't want to go back to the server and get a new set of data. What I want to do is just re-sort the data that is already being displayed.
Basically, I couldn't not find an easy solution to this issue. I tried updating my dataGrid to a gridView control and even that (for my particular issue) was difficult. I wound up un-doing all the changes and just adding another grid that had just the data I wanted for the requirement. If anyone else has an issue like this I would recommend taking it out of a datagrid and writing it in jQuery. I could of written a table that had the data I wanted (and fully sortable using a plug-in mentioned below) in 15 minutes compared to the hours I spent trying to jam a square peg into a round hole.
I have a GridView containing records from a table which can be deleted or updated. If you want to edit a row, it should display the update and cancel buttons so that you can keep or cancel the current edit (I hide update and cancel as default). I am using the following asp for the button column of the GridView:
<asp:TemplateField visible ="true" >
<HeaderTemplate>
<div id = "header">Maintain</div>
[code]...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
[Code]....
the row used to get in edit mode only if i edit the next row means first row never get in edited mode.