Link to home
Start Free TrialLog in
Avatar of dodgerfan
dodgerfanFlag for United States of America

asked on

ASP.Net Gridview behavior after update

I have an ASP.Net page (C# code behind, Access database) that displays 4 girdviews. I have two columns, side by side. The left column has starters on top, bench on bottom for batter (it's a baseball site). The right column has starters on top and bench on bottom for pitchers. The pitchers each have a button in their row, "Bench" in the starters gird, "Start" on the bench grid. Cliking this button changes a value in the underlying table in the starter field to 1 for starter, 0 for bench, When clicked the player is moved to the opposite grid, immediately. The grid displays the update very qucikly without a complete page refresh. These work fine. The batters grids do work properly. The batter bench grid also has a dropdownlist, an update button and a start button. The drop downlist displays all of the positions a player is quaified for. The user picks one, then clicks the update button to update the positinon. This seems to work, but its gets flaky at times so I'm not sure if its completely correct. If you click the Start button in the batter bench grid, he is moved to the Starter gird immeediately. But, if youbench someone from the starter gird, he is removed from starters but is not displayed in the bench. You have to completely refresh the page. I want the batter grids to behave as the pitcher grids do, displaying the changes immeditately without having to refresh the page. If possible, I would also prefer to have the batter bench grid dropdownlist update the table without having to click the update button. Is that possible? I've attached the code for the page, and any help is appreciated. Default2.aspx Default2.aspx.cs
ASKER CERTIFIED SOLUTION
Avatar of wls3
wls3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dodgerfan

ASKER

I have been trying to get the code to work within thr SelectedIndexChanged event, but I do not know how to grab the playerid of the individual records within the gridview. How can I do that?

 protected void ddlPos_SelectedIndexChanged(object sender, EventArgs e)
        {
            AccessDataSource ac = new AccessDataSource();
            GridView BenchGrid = (GridView)this.FindControl("BatterBenchGrid");
            String playerID = BenchGrid.DataKeys[int.Parse(e.ToString())].Value.ToString();

            DropDownList ddlPos = (DropDownList)BenchGrid.Rows[int.Parse(e.ToString())].FindControl("ddlPos");
           
            ac.DataFile = "~/App_Data/BaseballXP_Working.mdb";
            ac.UpdateCommand = "UPDATE vwBatterWorksheet SET PosNo = " + ddlPos.SelectedValue + " WHERE ID = " + playerID;
            ac.UpdateCommandType = SqlDataSourceCommandType.Text;
            ac.Update();
            DataBind();
       
       }
close enough.