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

  • Home
  • SEARCH
  • 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 8207811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:07:14+00:00 2026-06-07T09:07:14+00:00

I am a new ASP.NET developer and trying to use a GridView control to

  • 0

I am a new ASP.NET developer and trying to use a GridView control to show all the employees in the employee table in the database. I am working now in enabling updating the information in the GridView. I am facing the following probelm and I don’t know why:

**

Updating is not supported by data source ‘SqlDataSource1’ unless
UpdateCommand is specified.

**

FYI, I have the following database design:

Employee Table: Username, Name, JobTitle, BadgeNo, IsActive, DivisionCode
Divisions Table: SapCode, DivisionShortcut

(IsActive is like a flag (bit datatype) to indicate if the employee is in an assignment or not)

ASP.NET code:

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataKeyNames="Username" 
            DataSourceID="SqlDataSource1" BorderWidth="1px" BackColor="#DEBA84" 
             CellPadding="3" CellSpacing="2" BorderStyle="None" 
             BorderColor="#DEBA84" OnRowEditing="GridView1_RowEditing" 
             OnRowCancelingEdit="GridView1_RowCancelingEdit" 
             OnRowUpdating="GridView1_RowUpdating">
            <FooterStyle ForeColor="#8C4510" 
              BackColor="#F7DFB5"></FooterStyle>
            <PagerStyle ForeColor="#8C4510" 
              HorizontalAlign="Center"></PagerStyle>
            <HeaderStyle ForeColor="White" Font-Bold="True" 
              BackColor="#A55129"></HeaderStyle>
            <Columns>
                <asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true" />

                <asp:TemplateField>
                    <ItemTemplate>
                        <%# Eval("DivisionShortcut")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="DivisionsList" runat="server" DataSourceID="DivisionsListDataSource"
                                            DataTextField="DivisionShortcut" DataValueField="SapCode"></asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:BoundField DataField="Username" HeaderText="Network ID" ReadOnly="True" 
                    SortExpression="Username" />

                <asp:TemplateField>
                    <ItemTemplate>
                        <%# Eval("Name")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtEmployeeName" runat="server" Text='<%# Eval("Name")%>' />
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <ItemTemplate>
                        <%# Eval("JobTitle")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtJobTitle" runat="server" Text='<%# Eval("JobTitle")%>' />
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <ItemTemplate>
                        <%# Eval("BadgeNo")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtBadgeNo" runat="server" Text='<%# Eval("BadgeNo")%>' />
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <ItemTemplate>
                        <%# Eval("IsActive")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:CheckBox ID="isActive" runat="server" Text='<%# Eval("IsActive")%>' />
                    </EditItemTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:UsersInfoDBConnectionString %>" 

            SelectCommand="SELECT     dbo.Divisions.DivisionShortcut, dbo.employee.Username, dbo.employee.Name, dbo.employee.JobTitle, dbo.employee.BadgeNo, dbo.employee.IsActive
FROM         dbo.Divisions INNER JOIN
                      dbo.employee ON dbo.Divisions.SapCode = dbo.employee.DivisionCode">
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="DivisionsListDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:UsersInfoDBConnectionString %>" 
            SelectCommand="SELECT * FROM Divisions">
        </asp:SqlDataSource>

Code-Behind:

//For updating the information in any row in the GridView
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow gvrow = GridView1.Rows[e.RowIndex];

        DropDownList DivisionsList = (DropDownList)gvrow.FindControl("DivisionsList"); 

        TextBox txtEmployeeName = (TextBox)gvrow.FindControl("txtEmployeeName");
        TextBox txtJobTitle = (TextBox)gvrow.FindControl("txtJobTitle");
        TextBox txtBadgeNo = (TextBox)gvrow.FindControl("txtBadgeNo");

        CheckBox isActive = (CheckBox)gvrow.FindControl("isActive");

        //For getting the ID (primary key) of that row
        string username = GridView1.DataKeys[e.RowIndex].Value.ToString();

        string name = txtEmployeeName.Text;
        string jobTitle = txtJobTitle.Text;
        string badgeNo = txtBadgeNo.Text;

        UpdateEmployeeInfo(username, name, jobTitle, badgeNo);
    }


    private void UpdateEmployeeInfo(string username, string name, string jobTitle, string badgeNo)
    {
        try
        {
            string connString = ConfigurationManager.ConnectionStrings["UsersInfoDBConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(connString);
            string update = @"UPDATE Employee SET Name = @Name, JobTitle = @JobTitle, 
                                                BadgeNo = @BadgeNo 
                            WHERE Username = @Username";
            SqlCommand cmd = new SqlCommand(update, conn);

            cmd.Parameters.AddWithValue("@Name", name);
            cmd.Parameters.AddWithValue("@JobTitle", jobTitle);
            cmd.Parameters.AddWithValue("@BadgeNo", badgeNo);
            cmd.Parameters.AddWithValue("@Username", username);

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

            GridView1.EditIndex = -1;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

So could you please help me in modifying this?

  • 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-07T09:07:15+00:00Added an answer on June 7, 2026 at 9:07 am

    The SqlDataSource can do the updates in the database directly for you.

    You don’t need to capture the new values on row updating and do the updates on your own.

    For this you need to set the UpdateCommand

    Eg:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:UsersInfoDBConnectionString %>" 
        SelectCommand="SELECT dbo.Divisions.DivisionShortcut, dbo.employee.Username, dbo.employee.Name, dbo.employee.JobTitle, dbo.employee.BadgeNo, dbo.employee.IsActive
            FROM dbo.Divisions INNER JOIN dbo.employee
            ON dbo.Divisions.SapCode = dbo.employee.DivisionCode"
        UpdateCommand="UPDATE Employee SET Name = @Name, JobTitle = @JobTitle, BadgeNo = @BadgeNo
            WHERE Username = @Username">
    
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="JobTitle" Type="String" />
            <asp:Parameter Name="BadgeNo" Type="String" />
            <asp:Parameter Name="BadgeNo" Type="String" />
            <asp:Parameter Name="Username" Type="String" />
        </UpdateParameters>               
    </asp:SqlDataSource>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new ASP.NET developer and trying to use a GridView control to
I am a new ASP.NET developer and trying to use ASP.NET Ajax BallouPopupExtender with
I am a brand new Java developer (I have been working in asp.net) and
I'm new to ASP.NET (I'm a PHP developer) and I'm trying to understand how
I am a new ASP.NET developer and I am trying to change the value
I am a New ASP.NET Developer and I am trying to develop a simple
I am a new ASP.NET developer and I am trying to develop a simple
I am a new ASP.NET developer and I am developing a web-based suggestions box
I created a new ASP.NET website using Visual Web Developer 2008 Express edition and
I'm developer moving from C# to Java. Heard about new ASP net feature. <%:

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.