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

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

Gridview - Update with Dynamic SELECT Command?

Posted By:      Posted Date: October 09, 2010    Points: 0   Category :ASP.Net

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]";

View Complete Post

More Related Resource Links

GridView Update Command


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.

Command="Select" in GridView how to change color with css


How to change the selected row in GridView? Currently displayed yellow
I want to change the CSS color of selected row in the GridView.

I Command = "Select" when choosing a row, is shown in yellow.
I want to change that color.
What do I do?

How to perform insert, update, delete and select rows in ASP.NET gridview control using stored proce

In this article, we will explore how to add, update, delete and select a record from sql server database using gridview control in a simple way. I'm using visual studio 2010 and sql server 2008 for this sample.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

AJAX GridView Checkbox Select All in ASP.Net

In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

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.

Adding Dynamic Rows in GridView with TextBoxes

I decided to write this article because this has been asked so many times before at the forums(http://forums.asp.net) . Basically, this example shows on how to generate a Row in GridView with TextBoxes when clicking a Button that is residing inside a GridView Footer.

Adding Dynamic Rows in GridView with TextBoxex in C#

I decided to write this article because this has been asked so many times before at the forums(http://forums.asp.net) . Basically, this example shows on how to generate a Row in GridView with TextBoxes when clicking a Button that is residing inside a GridView Footer.

Select value in gridview


Hi, I am new to gridview. I want to make a gridview. Its row when selected should direct me to a specific .aspx page.Each row should direct to a different page. Should I use querystrings for this? Please suggest. Regards, ap.

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  

Select all checkboxes in gridview using Javascript


Hello members,


              I have used "Check box" inside the gridview...

              I need,

                           If i select the header check box , It should select all the checkbox inside the gridview...

              I have searched in google for this coding ...I got  lot of codes but couldn't get the correct code...

              I request anyone please provide me the correct code(using Javascript) thanks...

Gridview how do you select a row and colunm


I have a buttonfield button on my gridview, when I click of the buttons on one of the rows, from colunm[0] row[0] I need to display that contents in a textbox on another div and panel. How do I do that? 

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?

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