Solved

How to add rows to GridView by clicking on a button?

Posted on 2010-08-24
1
408 Views
Last Modified: 2013-11-05
Hi,

I'm developing a sharepoint custom field. In my class, which inherits from BaseFieldControl class, and particularly in the method "CreateChildControls", I created a DataTable, and I inserted two rows into it.
Also, I have a GridView with 4 columns. The dataSource for this GridView is the above DataTable.
Then, I have 4 text box fields and a button "Add".
When clicking on "Add" button, I create a new row with the values entered in the text box fields, then I add this row to the Datatable, then I rebind the datatable to the GridView as a DataSource.
 So the new row appears in the GridView.
But , if I fill in again the 4 fields and click on "Add", I got that the new row replaces, in the GridView, the row that I have added when I clicked on the "Add" button for the first time.
While, the required result is to see the second row with the first one in the GridView.
And, if I count the number of rows in the GridView, I found that the inserted rows by clicking on "Add" button are not considered.
So, how can I resolve it?

Thanks.
0
Comment
Question by:pgirardier
1 Comment
 
LVL 9

Accepted Solution

by:
rg20 earned 500 total points
Comment Utility
You would have to maintain a list of data as static data
or check that you don't remove it on postback

static List<string> data = new list<string>();
string record;
string newdata;

data.add(record);
data.add(record);
data.add(newdata);
data.add(newdata);

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now