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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:01:39+00:00 2026-05-24T03:01:39+00:00

I created this datagrid in my .aspx file. <asp:datagrid id=Computerchange runat=server AllowPaging=True PageSize=2 AutoGenerateColumns=False

  • 0

I created this datagrid in my .aspx file.

<asp:datagrid id="Computerchange" runat="server" AllowPaging="True" PageSize="2" AutoGenerateColumns="False" BorderColor="Gainsboro" Height="500px">
    <Columns>
        <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Admin Functions" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
        <asp:ButtonColumn Text="Delete" HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
        <asp:BoundColumn DataField="com_id" ReadOnly="True" HeaderText="Computer Number"></asp:BoundColumn>
        <asp:BoundColumn DataField="company" HeaderText="Company"></asp:BoundColumn>
        <asp:BoundColumn DataField="price" HeaderText="Price"></asp:BoundColumn>
        <asp:BoundColumn DataField="model" HeaderText="Model"></asp:BoundColumn>
        <asp:BoundColumn DataField="description" HeaderText="Description"></asp:BoundColumn>
        <asp:BoundColumn DataField="id" ReadOnly="True" HeaderText="Category"></asp:BoundColumn>
        <asp:BoundColumn DataField="quantity" ReadOnly="False" HeaderText="Quantity"></asp:BoundColumn>
        <asp:BoundColumn DataField="imgSrc" HeaderText="Image"></asp:BoundColumn>
    </Columns>
</asp:datagrid>

With this datagrid I want to edit-delete-update these columns in my database. When I have ReadOnly="False" in the quantity column then it works fine. I can Edit-Delete-Update everything. Sometimes I want to edit all the columns except QUANTITY. But when I convert it to True, then I have the following error when I click the Update button

Specified argument was out of the range of valid values. Parameter name: index

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index]

System.Web.UI.ControlCollection.get_Item(Int32 index) +8750274
AdminMainPage.Computerchange_UpdateCommand(Object source, DataGridCommandEventArgs e) +626
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +115
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +498
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +121
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +125
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169

System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Do you know why I have this error and what can I do to fix it? I wrote this function for the update Command

private void Computerchange_UpdateCommand(object source, 
System.Web.UI.WebControls.DataGridCommandEventArgs e)   
{
    //Store updated column values in local variables:

    //string updateCOM_ID = e.Item.Cells["com_id"].Text;

    string updateCOM_ID = e.Item.Cells[2].Text;

    string updateCompany = ((TextBox)e.Item.Cells[3].Controls[0]).Text;

    double updatePrice = double.Parse(((TextBox)e.Item.Cells[4].Controls[0]).Text);

    string updateModel = ((TextBox)e.Item.Cells[5].Controls[0]).Text;

    string updateDescription = ((TextBox)e.Item.Cells[6].Controls[0]).Text;

    int updateCategoryId = int.Parse(e.Item.Cells[7].Text);

    string updateImage = ((TextBox)e.Item.Cells[9].Controls[0]).Text;

    string updateQuantity = ((TextBox)e.Item.Cells[8].Controls[0]).Text;

    newView.RowFilter = "com_id='" + updateCOM_ID + "'";

    if (newView.Count > 0)
    {
        //Delete the row that is being updated

        newView.Delete(0);
    }

    newView.RowFilter = "";

    //Create a new DataRow and populate it with the new data.

    DataRow Row = Table.NewRow();

    Row["com_id"] = updateCOM_ID;

    Row["company"] = updateCompany;

    Row["price"] = updatePrice;

    Row["model"] = updateModel;

    Row["description"] = updateDescription;

    Row["id"] = updateCategoryId;

    Row["imgSrc"] = updateImage;

    //Row["quantity"] = updateQuantity;

    //Insert the new DataRow:

    Table.Rows.Add(Row);

    Computerchange.EditItemIndex = -1;

    Computerchange.DataSource = newView;

    Computerchange.DataBind();

    // Now update the database with the new data

    adminCentral1.adminCentral newData = new adminCentral1.adminCentral();

    string results;

    results = newData.updateItem(updateCOM_ID, updateCompany, updatePrice, updateModel, updateDescription, updateImage, updateCategoryId, updateQuantity);

    if (results == "Success")
    {
        errorLabel.Text = "Computer Updated to database!";
    }
    else
    {
        errorLabel.Text = results;
    }
  • 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-24T03:01:39+00:00Added an answer on May 24, 2026 at 3:01 am

    Because when ReadOnly="True" it renders only text, not a control, so Controls[0] throws an exception. Use a TemplateColumn instead:

    <asp:TemplateColumn HeaderText="Quantity">
    <ItemTemplate>
      <%# Eval("quantity") %>
    </ItemTemplate>
    <EditItemTemplate>
      <asp:TextBox runat="server" ID="tbQuantity" Text='<%# Eval("quantity") %>' ReadOnly="False" />
    </EditItemTemplate>
    </asp:TemplateColumn>
    

    You can set tbQuantity's ReadOnly property to true to disable editing.

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

Sidebar

Related Questions

I've created a Column button in datagrid using this code <Columns> <asp:ButtonColumn Text=Resend ButtonType=PushButton
I have a combobox inside of my WPF DataGrid. It is created like this:
I ve created columns of my datagrid using this, private void Receive_Load(object sender, System.EventArgs
I have followed this tutorial which allowed me to create a Silverlight DataGrid that
I created this program: #include <iostream> #include <fstream> using namespace std; int main ()
I created this layout of successive text input fields, 1- Enter data into empty
I have created this code, and when I run it, don't get any errors
I've created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so
I've created this simple GUI: from tkinter import * root = Tk() def grabText(event):
I've created this regex (www|http://)[^ ]+ that match every http://... or www.... but I

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.