3 Replies - 1528 Views - Last Post: 21 August 2012 - 07:02 PM Rate Topic: -----

#1 3P1C_F@!l  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 01-March 11

Update query not working when URL contains query string parms

Posted 21 August 2012 - 01:06 PM

I am running into a very odd issue with an SqlDataSource (actually two but that's neither here nor their). I have a page with a GridView control that is bound to an SqlDataSource. Initially the page loads and the GridView is not visible to the user until a string is entered into a TextBox and an option is selected from a DropDownList and the user clicks a button. Everything appears to be working fine on the surface until I re-create the process using query string parameters in the URL.

If you navigate to the page and run through the process manually the query returns data and you can also update the data in the grid. However, if you navigate to the page using a URL containing query string parms the select query runs and dumps data into the grid just fine and even allows you to update.. it just doesn't actually update anything when committing changes to the grid. Below is every bit of my code behind for said page.. what am I not seeing/doing here?

        protected void Page_Load(object sender, EventArgs e)
        {
            string qsFILENO = Request.QueryString["FN"];
            string qsTYPE = Request.QueryString["T"];

            if (qsFILENO != null && qsTYPE != null)
            {
                txtActNum.Text = qsFILENO;
                ddlTableName.ClearSelection();
                ddlTableName.Items.FindByValue(qsTYPE).Selected = true;

                btnSubmit_Click(null, null);
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string table = ddlTableName.SelectedValue;

            GridView1.DataSource = null;
            GridView1.DataBind();

            GridView2.DataSource = null;
            GridView2.DataBind();

            switch (table)
            {
                case "tecB":
                    GridView1.DataSourceID = "tecBDataSource";
                    GridView1.DataBind();
                    GridView1.Visible = true;
                    GridView2.Visible = false;
                    break;
                case "tecP":
                    GridView2.DataSourceID = "tecPDataSource";
                    GridView2.DataBind();
                    GridView2.Visible = true;
                    GridView1.Visible = false;
                    break;
            }

        }



Is This A Good Question/Topic? 0
  • +

Replies To: Update query not working when URL contains query string parms

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: Update query not working when URL contains query string parms

Posted 21 August 2012 - 05:58 PM

The problem is probably that because you are loading your grid during every page load all of the new values are getting overwritten before the code hits the update event. Try wrapping the part of the code in the page load that loads the grid inside of an if (!IsPostBack){} block
Was This Post Helpful? 0
  • +
  • -

#3 3P1C_F@!l  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 01-March 11

Re: Update query not working when URL contains query string parms

Posted 21 August 2012 - 06:13 PM

Thanks for the quick reply.. I feel like am idiot now. I can't believe this got past me. Also, sorry for negative feed back.. Meant to be positive but I fat fingered it from my phone. Hope a mod can fix that up for us.
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: Update query not working when URL contains query string parms

Posted 21 August 2012 - 07:02 PM

no problem and no worries on the rep thing
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1