0

I have a gridview which I used to display tabular data. I want the users to edit the field values and save it. Is there any way to add a textbox in place of bound field. This is my gridview.

   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
Height="186px" Width="325px">
          <Columns>       
          </Columns>
  </asp:GridView>

This is the code behind which populate the GridView

    public List<DataControlField> columns = new List<DataControlField>();
    public object DataSource { get; set; }

    protected void Page_Init(object sender, EventArgs e)
    {
        for (int i = 0; i < 10; i++)
        {
            BoundField bf = new BoundField() ; 
            bf.HeaderText = "LastName"  ; 
            bf.DataField = "LastName";

            columns.Add(bf);
        }

        foreach (DataControlField col in columns)
        {
            GridView1.Columns.Add(col);
        } 


    }
    protected void Page_Load(object sender, EventArgs e)
    {
        List<Data> lastN = new List<Data>() ; 
        for(int i = 0 ; i < 50; i++ )
        {
            lastN.Add(new Data(i.ToString())); 
        }
        GridView1.DataSource = lastN;
        GridView1.DataBind();
    }
}
1
  • any particular reason why you are creating columns at code-behind? Commented May 6, 2015 at 14:08

2 Answers 2

1

I would like to suggest you to try listview, it allows you to edit the dynamic data, such as the content in textbox

Sign up to request clarification or add additional context in comments.

1 Comment

Is it possible to auto-save the data in listview as you type ? I want to create an excel like grid which enables to auto-save.
0

You can use a GridView with EditTemplates. You can refer to this example for that.

It is possible to edit all rows of a GridView at the same time. Refer to this example.

You can optionally use Telerik's ASP.NET Data Grid that you can configure to work like excel using this example.

1 Comment

this is not the way we answer at SO. What you have given is only links to third party sites. This should be a comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.