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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:10:35+00:00 2026-05-27T18:10:35+00:00

I have a dynamically generated gridview with custom datasource. The gridview allows editing, inserting,

  • 0

I have a dynamically generated gridview with custom datasource.

The gridview allows “editing, inserting, and deleting”

Everything (all features) are working fine..

I then added a filtering feature to the gridview..

Let’s say previously my datasource is based on this select statement:

SELECT * FROM <Table>

Now, after filter:

SELECT * FROM <Table> WHERE <Filter Condition>

After filtering.. I am not able to do the editing (updating) gridview properly.. As during the editing mode..

   public void gvGridView_RowEditing(object sender, GridViewEditEventArgs e)
    {   
        gvGridView.EditIndex = e.NewEditIndex;
        ((TemplateField)gvGridView.Columns[1]).EditItemTemplate = null;
        //disable editing on primary key

        if (txtSearch.Text != string.Empty || CountRow() > 0)
        {
            FilterQuery(); //refilter the gridview
        }
        else
        {                
            gvGridView.DataBind();
            //if gridview is not meant to be filtered, just leave it as it is
        }
        Session["SelecetdRowIndex"] = e.NewEditIndex;
    }

Due to this line:

gvGridView.EditIndex = e.NewEditIndex;

The editindex will not be initialized correctly. For example:

  1. Before filter it was index no 8

  2. After filter it is index no 1

If i edit this gridview after filter what it will do is it will take 1 as the edit index (supposedly 8)… hence instead of updating data on index 8.. it will override data with index number 1…

I hope my question is clear enough.. looking forward to hear some answers :)..

Edit:

This what happens during gridview updating:

GridViewRow row = gvGridView.Rows[e.RowIndex];
//decide which row being edited..

for (int i = 0; i < Table.Columns.Count; i++)
        {
            string field_value = ((TextBox)row.FindControl(Table.Columns[i].ColumnName)).Text;
            ParameterArray.Add(field_value);
            //storing all value in that row into an array (including PK)
        }

The code above works fine (store all value into array) except for the primary key.. (always store e.rowindex value)..

  • 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-27T18:10:36+00:00Added an answer on May 27, 2026 at 6:10 pm

    In row updating event in cs page:

    protected void Grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       TextBox txtId = (TextBox)Grid.Rows[e.RowIndex].FindControl("txtId_insql");
       //Get the Id for which row is clicked
    }
    

    In aspx page:

    <Gridview>
    <column>
     <asp:BoundColumn DataField="txtId_insql" HeaderText="PrimaryID" Visible="False"></asp:BoundColumn> 
    </columns>
    </GridView>
    

    so you will get the ID.You can update using the Id now.Not with the Index.

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

Sidebar

Related Questions

I'm working on a web page where I have a dynamically generated table where
Is it possible to have checkboxes with a gridview that is dynamically generated from
i have a gridview layout, and all items are insert very fine, now if
I'm currently working on a Java web application, and have dynamically generated input boxes
Inside asp.net form I have few dynamically generated buttons, all of this buttons submit
I have a dynamically generated rss feed that is about 150M in size (don't
I have a list of dynamically generated div-tags with a class-attribute but no id.
I have a series of dynamically generated inputs that I need to have ajax
I have a form that is dynamically generated, and has dynamically generated id's (and
I have a requirement to display dynamically generated word document on the server in

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.