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 129955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:52:18+00:00 2026-05-11T05:52:18+00:00

I have a page, lets call it SourceTypes.aspx, that has a a GridView that

  • 0

I have a page, lets call it SourceTypes.aspx, that has a a GridView that is displaying a list of Source Types. Part of the GridView is a DataKey, SourceTypeID. If source TypeID is passed to the page via a query sting, how to I put the Gridview into Edit mode for the appropriate row based on the SourceTypeID?

The GridView is bound to a SQlDataSource object.

I have a feeling I am going to kick myself when the answer appears!!

I have looked at Putting a gridview row in edit mode programmatically but it is some what lacking in specifics

  • 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. 2026-05-11T05:52:19+00:00Added an answer on May 11, 2026 at 5:52 am

    First of all, many thanks to Steve Robins for getting me started down the right track. My approach was slightly different, partial due to the fact I was not using a DataBind method.

    I use a combination of the OnRowDataBound and OnDataBound events of the DataView. The OnRowDataBound event to determine the index of the row to be put into edit mode. The OnDataBound event sets the index and rebinds the DataView.

    A variable is used to ensure that the View is not continuously rebound.

    Here is the crux of the aspx page edited down for brevity.

    <asp:GridView ID='GridView1' runat='server'                DataSourceID='CreativeTypeDS'               AutoGenerateColumns='False'                DataKeyNames='SourceCreativeTypeID'                EmptyDataText='No Cretive Types at this time.'               CellPadding='3' CellSpacing='1'               OnRowDataBound='GridView1_RowDataBound'               OnDataBound='GridView1_DataBound' >         <Columns>            [Template Columns Here]         </Columns> </asp:GridView>  <asp:SqlDataSource ID='CreativeTypeDS' runat='server'                     SelectCommand='cmsSourceCreativeTypeSel'                    SelectCommandType='StoredProcedure'             UpdateCommand='cmsSourceCreativeTypeUpd'                    UpdateCommandType='StoredProcedure'>     <SelectParameters>                        <asp:Parameter Name='Active' DefaultValue='0' />     </SelectParameters>     <UpdateParameters>        <asp:Parameter Name='SourceCreativeTypeID' Type='Int32' />        <asp:Parameter Name='SourceCategoryID' Type='Int32'/>        <asp:Parameter Name='Name' Type='String' />        <asp:Parameter Name='Active' Type='Boolean' />      </UpdateParameters> </asp:SqlDataSource> 

    And now for the code behind.

     public partial class SourceCreativeTypes : System.Web.UI.Page  {     private int? EditIndex = null;     private bool GridRebound = false;     protected override void OnPreInit(EventArgs e)             {        CreativeTypeDS.ConnectionString = '[CONNECTION STRING MAGIC HERE]';     }      protected void Page_Load(object sender, EventArgs e)     {         if (IsPostBack)         {                             //Dont Want to set edit row manualy if post back             GridRebound = true;         }     }      //Use the Row Databound Event to find the row to put into edit mode      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)     {         if (!String.IsNullOrEmpty(Request.QueryString['ID']))         {             //Get Target ID from Query String             string sSourceCreativeTypeID = Request.QueryString['ID'];             //Get data for row being bound             DataRowView rowView = (DataRowView)e.Row.DataItem;              // Set index if we are in a 'normal row', the row data              // has been retrieved             // and the Supplied ID matches that of this row             if ((e.Row.RowState == DataControlRowState.Normal ||                  e.Row.RowState == DataControlRowState.Alternate)                  &&                 (rowView != null &&                   rowView['SourceCreativeTypeID'].ToString() == sSourceCreativeTypeID)                 )             {                                    EditIndex = e.Row.RowIndex;                                }         }     }      /* Use the Datbound Event to set the required row to index mode      * Then Rebind the grid. Rebinding in Row Databound does not work      * for Reasons unknown */     protected void GridView1_DataBound(object sender, EventArgs e)     {         //Set Gridview edit index if one is supplied and page is not a post back         if (!GridRebound && EditIndex != null)         {             //Setting GridRebound ensures this only happens once             GridRebound = true;             GridView1.EditIndex = (int)EditIndex;             GridView1.DataBind();         }      }    }  } 

    Hopefully between Steve and Myself we help a few of you out there

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

Sidebar

Related Questions

Here's my setup. I'm using .NET: I have a Main.aspx lets call it. That
We have some pages (lets call it parent pages) that calls to other .aspx
I have three Divs on the page and they are absolute positioned. Lets call
If I have a page with outputcaching (let's call it Employees.aspx) which accepts one
Lets say that I have a header user control in a master page, and
I have one webpage (lets call it A.html). A.html has some javascript which switches
Here's the scenario I have a page lets say login.aspx having a button called
I have an MVC 3 page that has two partial views, one for Items
Lets say we have an average of one page fault every 20,000,000 instructions, a
Lets say you have a fragment of the page which displays the most recent

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.