Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6183435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:21:54+00:00 2026-05-24T01:21:54+00:00

I want to conditionally call update statement on sqldatasource. I have a gridview and

  • 0

I want to conditionally call update statement on sqldatasource. I have a gridview and sqldatasource assigned to it. I handle gridview_updating event. If I do not assign sqldatasource.updatecommand to it (when some condition does not meet), I get error: “Updating is not supported by data source unless UpdateCommand is specified.”

How can I suppress this error message?

Thanks in advance:)

EDIT:

This is my command event of gridview:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {


            if (e.CommandName == "Update")
            { 
               if(someconditionmatch)
                  sqldatasource1.UpdateCommand = "some update query";
               else
               {
                   //do nothing...but when do do nothing...it throws error that some update command has to compulsorily assigned...This is my problem...which updateCommand should I assign if I do not want to update anything???
               }
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:21:56+00:00Added an answer on May 24, 2026 at 1:21 am

    Instead of handling this in the RowCommand event handler, you might try it in the RowUpdating event handler, because you can set the Cancel property to true:

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       if(someconditionmatch)
           sqldatasource1.UpdateCommand = "some update query";
       else
           e.Cancel = true; //Cancels the impending update.
    }
    

    I don’t know if you have to have the UpdateCommand with some value in the RowCommand event handler – if you do, you can always set the UpdateCommand to the one you use for the condition (assuming you have only one update command) in the RowCommand event handler (or the markup for the SqlDataSource), and then do the RowUpdating like this:

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       if (!someconditionmatch)
           e.Cancel = true;
    }
    

    Hopefully the above will help, or at least you get you pointed in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show a JQuery dialog conditionally on click event of an hyperlink
I have added some debugging code to my app which I want to call
I have a Silverlight control in MOSS (Sharepoint 2007) which I want to conditionally
I want to conditionally output HTML to generate a page, so what's the easiest
I want to conditionally navigate to some page. If some condition is true i
In my code, I want to conditionally perform a few operations with: #ifdef DEBUG
I'm building a carArray and want to filter the contents conditionally, using an NSPredicate
I want to use conditional binding in ninject, based on passed parameters. I have
I have some conditional formatting styles. I don't want to keep creating new rules
Is there a good way to chain methods conditionally in Ruby? What I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.