.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

GridView Update Command

Posted By:      Posted Date: September 28, 2010    Points: 0   Category :ASP.Net

I am trying to use an Update Command within my GridView.  I need to find the "FindControl" for the Edit Command textboxes.

Ie. When the user clicks the Edit button, the row is populated with dropdown boxes, textboxes, etc for editting. Then when the user clicks on Update (button) and the GridView1_RowCommand function is activated with 'if (e.CommandName == "Update")' statement with my FindControl. etc. and my sql UPDATE command statements are used.  How do I convert my FooterRow info to my Edit FINDCONTROL info?

This is what I have:

protected void GridView11_RowCommand(Object sender, GridViewCommandEventArgs e)

if (e.CommandName == "Update")


GridViewRow footer = GridView1.FooterRow;
            ddCityXXX = footer.FindControl("ddCityXXXInsert") as DropDownList;
            ddOvernightLSN = footer.FindControl("ddOvernightLSNInsert") as DropDownList;
            txtHotelName = footer.FindControl("txtHotelNameInsert") as TextBox;
            txtHotelAdd = footer.FindControl("txtHotelAddI") as TextBox;
            txtHotelCity = footer.FindControl("txtHotelCityI") as TextBox;
            txtHotelState = footer.

View Complete Post

More Related Resource Links

Gridview - Update with Dynamic SELECT Command?


Hi All...

We created a GridView-based webform with Update using the design wizards - very nice and it works great.  But then we wanted to the ability to create the SELECT command dynamically based on other controls on the page.  We added something like the following to Page_Load()...

            SqlDataSource1.SelectCommand = "SELECT [StationId], [IP] FROM [Stations]";

The GridView populates normally, but the Update no longer works.  It changes the "Edit" link to "Update", gives the user the edit boxes, but when "Update" is clicked it never seems to write the new data to the database.  No error - it just doesnt work...

Any thoughts?  How can we change the SELECT command (and Connection String) dymamically and still retain the Update functionality?

Many thanks - Curt.  Code follows...

    protected void Page_Load(object sender, EventArgs e)
        //  Doesn't work with or without this conditional
        //if (!IsCallback)
            SqlDataSource1.SelectCommand = "SELECT [StationId], [IP] FROM [Stations]";

ASP.Net Gridview Edit Update Cancel Commands

In ASP.Net 2.0, GridView Control also provides the functionality to edit and update the data retrieved from the database using CommandField template. You can cancel the action using Cancel Command of the CommandField. GridView consists of events that can be used to perform the actions like edit, update and cancel upon the Data items displayed in the ASP.Net GridView Data Control.

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.

Add, Edit, update, Delete gridview

The article Add, Edit, update, Delete gridview was added by anjankant on Friday, July 09, 2010.

Thousandas operation we can do on Gridview control. Here I as explaining how we can add new recored and edit of existing record and delete a record in Gridview. Step1 : You can add this gridview in your aspx form. Here some events of Gridview are fired

update parentpage gridview with the values from child page?


hi   i am having a gridview on each row i am having a update and add button.

on click of either of the button i am opening a popup where the end user will enter data and on clck of ok button in the child page

based on the click ie

if i clicked update i need to update that particular row with the values from child page.

if i clicked on add i need to add a row below the row where i clicked add button .

can anyone help me with this?

Multiple update statements per row in Gridview Edit


I want to set up a gridview that will display data like this

WeekEndingDate Project Category Sun Mon Tues Wed Thu Fri Sat
8/14/2010      proj1   test     2   1   2    3   2   1   0
8/21/2010      proj1   test     0   2   2    2   2   1   0
8/28/2010      proj1   test     0   1  

Gridview Update outside of SqlDatasource


Is it possible to use a SQLDataSource to populate a gridview but not use the SQLDataSource for Updating?

I wanted to add the update code in the Gridview_RowUpdating event since it is a complex update I need to do.

I get this message when i click the update button

Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.

Changing a textbox's readonly property right before update on a gridview


I have a gridview with a date field. I don't want the user to be able to type in their own date and mess up the format so I made the property readonly. That date is then set by a point and click interface. This is all working fine but when the user clicks update this field doesn't update because it's readonly. If i turn readonly off it works so is there a way to turn off the readonly property right before submit?

I need to set the value of a gridview cell during update.

Hi,  I've been reading the posts here and I'm not finding, or maybe just not understanding, the answer I need so here's my problem. I have a small gridview and the update works very well. The issue is I need to have one of the fields set to a value from my code either when the record is open for undating or when the update runs.  Here is my gridview and the datasource info:<asp:GridView ID="GridViewItemLog" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" CellPadding="3" DataKeyNames="LogID" DataSourceID="SqlDataSourceItemLogEntries" GridLines="Vertical" onrowdatabound="GridViewItemLog_RowDataBound" onrowupdating="GridViewItemLog_RowUpdating" onrowediting="GridViewItemLog_RowEditing"><AlternatingRowStyle BackColor="Gainsboro" /><Columns><asp:CommandField ButtonType="Image" CancelImageUrl="~/Resources/StopSmall.png" EditImageUrl="~/Resources/EditSmall.png" ShowEditButton="True" UpdateImageUrl="~/Resources/Save.png" /><asp:Boun

Gridview's in Update Panel not updating

I 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:</head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Timer ID="Timer1" runat="server" Interval="300000" Enabled="True"> </asp:Timer> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> <ContentTemplate> <table class="style1"> <tr>

binding datetimecontrol,dropdown,textbox inside gridview and update each gridviewrow

i have a web part with datetimecontrol(sharepoint) inside a  gridview. when the page loads this this gridview will be loaded with dtc control and the selecteddate would be one of the columns in the splist.also gridview contaisn dropdowns, textboxes, when an update button cliked inside grid, i need to save the info in the splist.  currently i am not getting the value  bound with dtc control. i am getting blank date inside dtc. though in the  rowdatabound event i amcapturing the values due to some reason i am not able to view the value in the DTCcontrol. can anybody give me help me how to achieve this? any  help links/ sample code.. appreciate the help                         

Update a field in a gridview to False on a Button Click

 Hi, Ive got a list of records in a gridview (from an SQLDataSource) where a field value is set to True.  I've also added a "reset" button in a template field at the start of the row in the Gridview. What I would like to do is allow the user to click the reset button on a particular row and 'reset' the true value to 'false' (updating the source data). Are there any idiot proof tutorials to do this??? Many thanks for your help! Fiorano

declarative #Bind doesn't bind in update command

I have a bunch of controls like the following in the EditItemTemplate of a ListView, with LINQDataSource:<asp:TextBox ID="Email" CausesValidation="true" EnableViewState="False" Font-Bold="false" Text='<%#Bind("Email")%>' BackColor="#FFFFFF" Enabled="true" TabIndex="50" runat="server" /> I'm curious to know why the database won't update on the click of the Update button:<asp:Button ID="btnUpdate" CommandName="Update" Text="Update" UseSubmitBehavior="False" TabIndex="170" runat="server" /> According to all I've read, the above code should be sufficient. Since CommandName is set to Update, it would seem that no code-behind is necessary.

Update Database Record using GridView and Stored Procedure

Hi, I am trying to update record via stored procedure, but i got error at very start point. Problem is when i click on Edit link button within the Gridview it produce error. I can populate values from database fine but its produce error when i click on edit link button. Please see the code below. *********** ASP.net GridView Code I am using *****************<asp:GridView ID="GridView1" runat="server" DataKeyNames="RollID, EmpID" AutoGenerateColumns="False" Width="700px"> <Columns> <asp:TemplateField HeaderText="ApplicationID" Visible="false"> <ItemTemplate> <asp:Label ID="AppsID" runat="server" Visible="false"><%# Eval("RollID") %>'</asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="ReleaseID" Visible="false"> <ItemTemplate> <asp:Label ID="rlsID" runat="server" Visible="false"><%# Eval("EmpID") %></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Roll Name"> <ItemTemplate> <asp:Label ID="rlsVersion" runat="server"><%# Eval("Roll_Name")%></asp:Label> </ItemTemplate> <EditI

SQL Update command on button click

Hello!I don't know what is the problem with my code. SQL statement is good (I checked it outside of the application) but for some reason it doesn't update the data.Let me explain a bit better. I have a web form which is supposed to be used for editing data in textboxes and on button click the data should be updated via SQL query.public partial class Administracija_Clanak : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string ClanakID = Page.Request.QueryString["idClanak"]; String connString = WebConfigurationManager.ConnectionStrings["CMS"].ToString(); SqlConnection conn = new SqlConnection(connString); conn.Open(); using (SqlCommand command = new SqlCommand("SELECT Clanak.* , Kategorije.naziv FROM Clanak Clanak INNER JOIN Kategorije ON Clanak.idKategorije = Kategorije.idKategorija WHERE Clanak.idClanak='" + ClanakID + "'", conn)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { txtIDClanak.Text = reader.GetInt32(0).ToString(); ddlKategorija.Text = reader.GetInt32(1).ToString(); txtNaslov.Text = reader.GetString(2).ToString(); txtAutor.Text = reader.GetString(4).ToString(); txtSadrzaj.Content = re

Gridview Update and Cancel not visible

Hi, I am having a strange problem. I put on a Gridview on my aspx page. I also data bound it to a table from my SQL server.   Other than that I wanted to put in the Edit, Update and Cancel functionality so I also put in this from the Gridview Smart Tag. Following is the gridview aspx code can anyone tell me what I am missing here?     <asp:GridView ID="GridView1" OnRowEditing="grdQLOnRowEditing" runat="server" OnRowCommand="grdQLOnRowCommand" AutoGenerateColumns="False" Width="482px" OnRowCancelingEdit="grdQLOnRowCancel" OnRowUpdating="grdQLOnRowUpdating" > <Columns> <asp:TemplateField HeaderText="UrlId"> <ItemTemplate> <asp:Label ID="lblUrlId" runat="server" Text='<%# Eval("URLId") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Title"> <ItemTemplate> <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>

how to update GridView using jquery

i search a id =99  that data display on Grid view using jquery Ajexhow to update GridView using jquery
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend