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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:04:29+00:00 2026-06-15T11:04:29+00:00

Could someone post a working example of a gridview with all rows editable (like

  • 0

Could someone post a working example of a gridview with all rows editable (like it was an excel) and list<type> as datasource?

We want to mantain the data the user inputs in the grid between postbacks (that may be generated by any control not only the submit one) and then get the data from the list or the gridview so we use it to insert or update different tables (this is not the typical case of 1:1 relation / grid:sqltable)

Also we have a dropdownlist (with autopostback) with numbers 1 to 9 that controls how many rows are used in the gridview, so if the users changes from 1 to 5 rows 4 new rows will be added to the gridview and if he changes from 8 to 5 rows the last 3 rows will be deleted…(mantaing the data currently inputed by the user)

Thanks beforehand

  • 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-15T11:04:31+00:00Added an answer on June 15, 2026 at 11:04 am

    Solved it like this:
    ASPX:

     <asp:DropDownList ID="ddlNItems" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlNItems_SelectedIndexChanged">
         <asp:ListItem Selected="True">1</asp:ListItem>
         <asp:ListItem>2</asp:ListItem>
         <asp:ListItem>3</asp:ListItem>
         <asp:ListItem>4</asp:ListItem>
         <asp:ListItem>5</asp:ListItem>
         <asp:ListItem>6</asp:ListItem>
         <asp:ListItem>7</asp:ListItem>
         <asp:ListItem>8</asp:ListItem>
         <asp:ListItem>9</asp:ListItem>
     </asp:DropDownList>
    
     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True">
         <Columns>
             <asp:TemplateField HeaderText="Código">
                 <ItemTemplate>
                     <asp:TextBox ID="txtCodMuestra" runat="server" Text='<%# Eval("cod") %>' /></ItemTemplate>
                 </asp:TemplateField>
              <asp:TemplateField HeaderText="Tipo">
                  <ItemTemplate>
                      <asp:DropDownList runat="server" ID="ddlTipo" SelectedValue='<%# Eval("Tipo") %>'>
                          <asp:ListItem Value="a">A</asp:ListItem>
                          <asp:ListItem Value="b">B</asp:ListItem>
                          <asp:ListItem Value="c">C</asp:ListItem>
                      </asp:DropDownList>
                  </ItemTemplate>
              </asp:TemplateField>
          </Columns>
      </asp:GridView>
    

    CS:

    public class Itemx
    {
        public string cod { get; set; }
        public string Tipo { get; set; }
    }
    public static List<Itemx> LItems
    {
        get
        {
            return (List<Itemx>)Session["LItems"];
        }
        set
        {
            Session["LItems"]= value;
        }
    }
    void InitializeItems()
    {
        LItems = new List<Itemx>();
        ConfigItems();
    }
    void ConfigItems()
    {
        int numitems = Convert.ToInt32(ddlNItems.SelectedValue);
    
    
        if (LItems.Count > numitems )
        {
            for (int i = GridView1.Rows.Count; i > numitems; i--)
            {
                LItems.RemoveAt(i - 1);
            }
        }
        else if (LItems.Count < numitems )
        {
            for (int i = GridView1.Rows.Count; i < numitems; i++)
            {
                LItems.Add(new Itemx { Tipo = "a" });
            }
        }
        transferGridtoList();
    
        GridView1.DataSource = LItems;
        GridView1.DataBind();
    
        GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
    }
    private void transferGridtoList()
    {
        for (int i = 0; i < LItems.Count && i < GridView1.Rows.Count; i++)
        {
            LItems[i].cod = ((TextBox)GridView1.Rows[i].Cells[0].Controls[1]).Text;
            LItems[i].Tipo = ((DropDownList)GridView1.Rows[i].Cells[1].Controls[1]).SelectedValue;
        }
    }
    
    protected void ddlNItems_SelectedIndexChanged(object sender, EventArgs e)
    {
        ConfigItems();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please could someone post an example of how to check if an element exists
I'm hopeful that someone could potentially post an example of using FParsec where the
Could someone post a link to simple tutorial, which describe how to use User
first time post here. I was hoping someone could help me make custom SPARQL
I wonder whether someone could help me please. I've been working on, and I've
Could someone know where is saved path to external XML-File that contain configuration for
Could someone please tell me why this <%= destroy_password_url @user.password_reset_token %> generates http://localhost:3000/api/destroy_password.4G5EoRVYMUAtiIKqOerKsw routes.rb
Could someone please suggest why this is happening... I’ve got some code to pretty
Could someone help me to add A-atype B-btype C-ctype ONLY as a legend to
Could someone provide a sample implementation for rotating a button on a thread ?

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.