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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:17:26+00:00 2026-05-19T13:17:26+00:00

public partial class Gridvw_expt2 : System.Web.UI.Page { SqlCommand com; SqlDataAdapter da; DataSet ds; SqlConnection

  • 0
public partial class Gridvw_expt2 : System.Web.UI.Page
{
   SqlCommand com;
   SqlDataAdapter da;
   DataSet ds;
   SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["gj"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{


    com = new SqlCommand("Select * from tblExpt",con);
    da = new SqlDataAdapter(com);
    ds = new DataSet();
    da.Fill(ds);
    if (ds.Tables[0].Rows[0] != null)
    {
        GridView1.AutoGenerateEditButton = true; 
        GridView1.DataSource = ds;
        GridView1.DataBind();
        GridView1.RowUpdating += new GridViewUpdateEventHandler(GridView1_RowUpdating);
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.RowEditing += new GridViewEditEventHandler(GridView1_RowEditing);

    }
    else
        Response.Write("fkj");
}

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = GridView1.Rows[e.RowIndex];
    int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);

    string cls = ((TextBox)(row.Cells[2].Controls[0])).Text;
    string nam = ((TextBox)(row.Cells[3].Controls[0])).Text;
    foreach (DictionaryEntry entry in e.NewValues)
    {
        e.NewValues[entry.Key] = Server.HtmlEncode(entry.Value.ToString());
    }
    com = new SqlCommand("Update tblExpt set name='" + nam + "',class='" + cls + "' where id='" + id + "'", con);
    da = new SqlDataAdapter(com);
    GridView1.EditIndex = -1;
    GridView1.DataSource = ds;
    GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;
    GridView1.DataSource = ds;
    GridView1.DataBind();
}

}

In the above code when i try to access e.new values index out of range exception is thrown.

The table being accessed contains 3 fields id, class, name
Please help to solve the problem.

  • 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-19T13:17:27+00:00Added an answer on May 19, 2026 at 1:17 pm

    Read this blog post I wrote on extracting data from gridview (and other data controls). Also, in .net 4.0 if you use 2 way binding (<# Bind(“”) #>) e.NewValues will be populated.

    More info here: http://weblogs.asp.net/davidfowler/archive/2008/12/12/getting-your-data-out-of-the-data-controls.aspx

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

Sidebar

Related Questions

public partial class Table_Traversing : System.Web.UI.Page { Table table1 = new Table(); TableRow table_row1
The code public partial class Table_Traversing : System.Web.UI.Page { Table table1 = new Table();
In Silverlight I noticed that the code-behind Page class inherits from UserControl: public partial
You should be able to create a generic form: public partial class MyGenericForm<T> :
I have a control that is created like so: public partial class MYControl :
I've got the following Generic usercontrol declared: public partial class MessageBase<T> : UserControl {
public partial class Form1 : Form { bool AfterDocumentCompleted = false; int steps =
I have the following object: public partial class Game { public bool Finished {
I have customizable object class I'd like to serialize: public partial class CustomObject {
I am populating a DropDownList control as follows - public partial class UserControls_PMS_Send2DeliveryTeam :

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.