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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:50:25+00:00 2026-06-10T14:50:25+00:00

I have a GridView which has the property: OnRowUpdating=GridViewRowUpdateEventHandler Within the GridView, I have

  • 0

I have a GridView which has the property:

OnRowUpdating="GridViewRowUpdateEventHandler"

Within the GridView, I have the following control:

<asp:TemplateField HeaderText="Progress" SortExpression="progress">
    <ItemTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
            <asp:ListItem Value="0">Incomplete</asp:ListItem>
            <asp:ListItem Value="1">Complete</asp:ListItem>
        </asp:DropDownList>
    </ItemTemplate>
</asp:TemplateField> 

The GridViewRowUpdateEventHandler looks like this:

protected void GridViewRowUpdateEventHandler(object sender, GridViewUpdateEventArgs e)
{
    SqlConnection connection;
    SqlCommand command;

    GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];

    DropDownList ddlPriority = (DropDownList)row.FindControl("DropDownList1");

    using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
    {
        using (command = new SqlCommand(@"update table1 set priority = @priority where id = @id", connection))
        {
            command.Parameters.Add("@priority", SqlDbType.Int, 1).Value = ddlPriority.SelectedValue;
            command.Parameters.Add("@id", SqlDbType.Int, 1).Value = row.RowIndex;

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
    }

    GridView1.DataBind();
}

I am getting no error messages at all, and the relevant row in the database is not being updated. Anyone know why?

Could it be that I am looking at the wrong cell Cells[5]? Or maybe because I have nothing in page_load? Or maybe something else?

  • 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-06-10T14:50:27+00:00Added an answer on June 10, 2026 at 2:50 pm

    Since the DropDiownList is in a TemplateField and it’s NamingContainer is the GridViewRow, you should use row.FindControl to get the reference:

    DropDownList ddlPriority = (DropDownList)row.FindControl("DropDownList1");
    

    instead of

    DropDownList ddlPriority = (DropDownList)row.Cells[5].FindControl("DropDownList1");
    

    But that is not the core of your problem since row.Cells[5].FindControl might work also when it is in the 6th cell. Otherwise you would get a NullreferenceException.

    I assume that you are also binding the GridView on postbacks, you should check the IsPostBack property:

    protected void Page_Load()
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    

    Apart from that:

    command.Parameters.Add("@id", SqlDbType.Int, 1).Value = row;
    

    Does not work because row is the GridViewRow. You should also DataBind your GridView at the end, otherwise the changes won’t be reflected.

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

Sidebar

Related Questions

I have a gridview within an updatepanel which allows paging and has a linkbutton
I have a gridview which has an asp image-button for deleting a row. I
I have a GridView which has following template field that holds the filename, when
I've got an asp:DataGrid which has an asp:Gridview within it and this has many
For example, Lets say that I have a gridview column which has important controls,
I have a GridView in which each row has a custom view. The grid
I have a GridView on a .aspx page with a hidden column which has
ok i have a project which has many gridview in its pages... now i
Have a gridview control which will show X amount of rows. I want to
I have one GridView gvDetail which has 30 columns(include both Template and BoundField). 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.