The gridview fails to update when I attempt to click on the update button

Here is my updated code snippet for the GridView

After clicking on the update button, the gridview is not being updated and instead reverting back to its previous value. However, the delete option is working correctly.

        Id = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblDealerId")).Text;
        Name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDealer_Name")).Text;
        Address = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDealer_Address")).Text;
        City = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity")).Text;
        Pincode = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDealer_Pincode")).Text;

        string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
        SqlConnection con = new SqlConnection(cs);

        SqlCommand cmd = new SqlCommand("sp_update_dealer", con);
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add("@dealer_id", SqlDbType.NVarChar).Value = Id;
        cmd.Parameters.Add("@dealer_name", SqlDbType.NVarChar).Value = Name;
        cmd.Parameters.Add("@dealer_address", SqlDbType.NVarChar).Value = Address;
        cmd.Parameters.Add("@dealer_city", SqlDbType.NVarChar).Value = City;
        cmd.Parameters.Add("@dealer_pincode", SqlDbType.NVarChar).Value = Pincode;

        //GridView1.EditIndex = -1;
        cmd.Connection = con;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();

Answer №1

Make sure that your lblDealerId label is included in the EditTemplate section as well:

<EditItemTemplate>
    <asp:Label ID="lblDealerId" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
    //.. other input fields here
</EditItemTemplate>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using v-model in a child component and setting v-model within a child component in a Vue project

How can I simplify this code? Ensure that the button also updates the localValue of the child component. Vue.component('my-input', { template: ` <div> <b>My Input:</b> <br> localValue: {{ localValue } ...

AngularJS: Error message stating that '$scope is undefined'

Encountering '$scope is not defined' console errors in this AngularJS controller code: angular.module('articles').controller('ArticlesController', ['$scope', '$routeParams', '$location', 'Au ...

How to rotate text direction using JavaScript and CSS

Despite my extensive efforts, I have been unable to find a solution to a seemingly simple problem. In JavaScript, I have generated dynamic text using the following code: context.fillText('name', 10, 10, 20); Now, I need this text to be ori ...

Transform a string into an array using JavaScript

Currently, I am dealing with an array: itemSku = ["MY_SERVICE","SKU_A","SKU_B"]; When passing this value to a component in Angular, the type of itemSku is being identified as a string. This prevents me from performing array operations on it. console.log ...

Ways to modify React icons upon clicking them?

Dealing with some icons from react-icons that seem to be causing trouble. Whenever I try to change an icon from outline to filled upon clicking, all the icons end up changing together. It's not functioning as expected. Take a look at my code snippet ...

Dealing with an endless loop caused by a promise in AngularJS's ui router $stateChangeStart event

I am currently working on implementing authentication in my Angular application and I want to redirect to an external URL when a user is not logged in (based on a $http.get request). However, I seem to be stuck in an infinite loop when using event.prevent ...

What sets Legacy JavaScript apart from its modern counterpart, JavaScript?

Exploring the distinctions in coding practices between JavaScript and jQuery, I came across an interesting concept known as Legacy JavaScript that I was previously unaware of. You can read more about it at this link: Selecting Elements in Different Ways: ...

Is Jquery Mobile's Table lacking responsiveness?

I have implemented a basic table from the jQuery Mobile website on my page. Take a look at the HTML code below: <div data-role="page" id="mainPage"> <div data-role="content> <table data-role="table" id="my-table" da ...

Move a 'square' to a different page and display it in a grid format after clicking a button

I am currently developing a project that allows students or schools to add projects and search for collaborators. On a specific page, users can input project details with a preview square next to the fields for visualization. Once the user uploads the ...

Tips for Editing and Modifying Name and Area in a Database

I'm currently working with React to develop a full CRUD application, but I'm facing challenges in updating the names and areas of rooms within houses. Any suggestions or insights on how to achieve this would be greatly appreciated. Apologies for ...

Error: Unable to access the 'rotation' property of an undefined object in the animate function on line 266 of index.html, at line 287 of index.html

I am facing an error when trying to animate a model with rotation or position in my code. I attempted to create an init function to run everything, but it did not resolve the issue. The error only appears during animation; once the animation stops, the e ...

The validation for Australian mobile numbers should include the option to have spaces between the digits

How can I validate a mobile number properly? The first text input should start with 04 It should have a total of 10 digits, including 04 (e.g. 0412345678) Below is my input field: <form name="uploadForm"> <input type="tel" name="MobileNumber" ...

Show the helper text when a TextField is selected in Material UI

I would like the error message to only show up when a user clicks on the TextField. Here's my code: import React, { useState, useEffect } from 'react'; import { TextField, Grid, Button } from '@material-ui/core'; const ReplyToComm ...

Using NextJS getServerSideProps to Transfer Data to Page Component

Having trouble with my JavaScript/NextJS code, and not being an expert in these technologies. I'm using the method export const getServerSideProps: GetServerSideProps = async () => {} to fetch data from an integrated API within NextJS. The code mig ...

Child component not displaying React props (although I can identify them in debug mode)

Currently, I am working on a React project that does not involve Redux. However, I am encountering some difficulties in passing the state from the parent component to the child component. Despite watching numerous tutorials and extensively using the Chrome ...

Is there a way to retrieve both the items within a specific category and its corresponding subcategories simultaneously?

Presently, I am managing two models for Category and subcategory. The category model provides an array of data as shown below: category = [ {_id: '1', name: 'Appliances', slug: 'appliances'}, {_id: '2', na ...

Trouble with triggering Ajax file upload progress event

Using AJAX request, I am splitting and uploading a file in chunks. However, I have encountered an issue with the progress event not firing in Firefox. Below is the relevant code snippet: //slice file if(file.mozSlice){ chunk = file.mozSlice(startByt ...

The AngularJS directive within a directive is failing to properly initialize the scope value

In my current setup, I am working with a controller that contains the value $scope.colorHex. As an example, I am utilizing the directive colorpickerTooltip, and within its template, I am calling another directive: <colorpicker ng-model="colorHex">&l ...

Bootstrap allows for the use of video backgrounds, offering the option for borders to be included

Having trouble with a Bootstrap HTML page featuring a video background? The issue is that sometimes the video has borders on the left and right, and occasionally on mobile devices as well. Oddly enough, when the browser (Chrome or Firefox) is refreshed, th ...

Switch between different table rows

I have here a table that is used for displaying menu and submenu items. It's a mix of PHP (to fetch the menu items and their respective submenus) and HTML. What I am trying to figure out is how to toggle the visibility of only the submenu items under ...