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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:21:21+00:00 2026-05-23T00:21:21+00:00

I have binded a data grid to an array. Also, there is a button

  • 0

I have binded a data grid to an array. Also, there is a button there to delete the row. The problem is that I am not sure how to implement it since the data source is an array.

See below

  <Columns>    
     <asp:TemplateColumn>        
            <ItemTemplate>          
       <asp:Label ID="lblItems" runat="server" Text='<%# Container.DataItem>' />         
       </ItemTemplate>    
     </asp:TemplateColumn>     
        <asp:ButtonColumn ButtonType="PushButton" CommandName="Delete" Text="Delete">
          </asp:ButtonColumn>
                 </Columns> 

and here I would like to implement it..

   private void DataGrid1_DeleteCommand(object source,
                  System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        int rowToDelete = e.Item.ItemIndex;

        myDataGrid.DataBind();
    }

In the code for the deletion, how can I access the index of my array based on the button clicked (per row)?

  • 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-23T00:21:21+00:00Added an answer on May 23, 2026 at 12:21 am

    Here is an example

    Markup.

    <asp:DataGrid ID="DataGrid1" runat="server"
            AutoGenerateColumns="False" 
            OnDeleteCommand="DataGrid1_DeleteCommand">
        <Columns>
            <asp:TemplateColumn HeaderText="Name">
                <ItemTemplate>
                    <asp:Label ID="lblItems" runat="server" 
                        Text='<%# Container.DataItem %>'>
                    </asp:Label>
                </ItemTemplate>
            </asp:TemplateColumn>
            <asp:ButtonColumn ButtonType="PushButton" 
                    CommandName="Delete" 
                    HeaderText="Actions" 
                    Text="Delete">
            </asp:ButtonColumn>
        </Columns>
    </asp:DataGrid>
    

    Code-behind.

    private static string[] names = new string[] { "Matt", "Joanne", "Robert" };
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            BindGrid();
        }
    }
    private void BindGrid()
    {
        DataGrid1.DataSource = names;
        DataGrid1.DataBind();
    }
    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
    {
        string deletedItem = ((Label) DataGrid1.Items[e.Item.ItemIndex].FindControl("lblItems")).Text;
        names = names.Where(val => val != deletedItem).ToArray();
        BindGrid();
    }
    

    Hope this helps.

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

Sidebar

Related Questions

Here is the problem: I have datagrid binded with data acquired from web service
I have an EditorGridPanel with a CheckboxSelectionModel. In the Ext.data.Source binded to this grid,
I have a data grid and I am data bindding it to an array
If I have a grid, and it is binded to some data, but the
I have binded the accdb to combobox but it can not bind the data
I have a listbox that's binded to data, each item that's in the listbox
I have created 2 dropdownlists that are binded to a SQL DB and then
I have a listview that is binded to a ThreadSafeObservableCollection. The background of each
I have a collection that is binded to my Listview. I have provided options
I have a Button and the button content is binded to a custom class

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.