473,796 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding data to an existing gridview

17 New Member
I am trying to add data to an existing gridview, the gridview already has defined columns and I need to add data to these columns.

However when I use gridview.dataso urce, it just adds new columns to the gridview. It is properly not that hard to do this, but I have been hammering my head on this problem for the last three days and I haven’t been able to find any help on Google.

I have added the code I have already made and it works ok, it just adds new columns instead of putting the data in the existing columns.

Expand|Select|Wrap|Line Numbers
  1. private void GridViewFunktion()
  2.         {
  3.  
  4.             DataColumn colOrigName = new DataColumn("Original_Name");
  5.             DataColumn colNr = new DataColumn("Nr");
  6.             DataColumn colSystem_Hop = new DataColumn("System_Hop");
  7.             DataColumn colType = new DataColumn("Type");
  8.  
  9.  
  10.             myTable.Columns.Add(colOrigName);
  11.             myTable.Columns.Add(colNr);
  12.             myTable.Columns.Add(colSystem_Hop);
  13.             myTable.Columns.Add(colType);
  14.  
  15.             varStringedt = OtherFunktions.VARSTRINGEDT;
  16.  
  17.             for (int i = 0; i < varStringedt.Length; i++)
  18.             {
  19.                 DataRow myRow;
  20.                 myRow = myTable.NewRow();
  21.                 myRow["Original_Name"] = varStringedt[i];
  22.  
  23.  
  24.                 myTable.Rows.Add(myRow);
  25.             }
  26.  
  27.             ReMk1_SE_dataGridView.DataSource = myTable;
  28.         }
  29.  
Aug 30 '09 #1
1 6496
GaryTexmo
1,501 Recognized Expert Top Contributor
Just because two DataColumn objects have the same text name doesn't mean they're the same object. You're actually creating 3 brand new columns and putting them into myTable, which you then hook to your DataGridViewobj ect.

Also, if you call the above function more than once you're actually going to get more copies of your columns, since you're creating new DataColumn objects every single time.

I'd suggest having the columns be completely defined by the DataTable and have DataGridView empty... or build the columns for the DataTable based on what's in the DataGridView, then clear the DataGridView columns before you set it's DataSource

Does that make any sense or help you at all? I changed my thought process a few times in there so I realize I may be rambling a bit.
Aug 31 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4911
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are: (1)Is it a good idea to add new columns to the existing table? then it will create these new columns for all old records, will it not result in wasting a lot of space?? (2)Is it a good idea to create a new table with the new information and have as a...
4
5097
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. Thanks Hans
0
1452
by: AboutJAV | last post by:
I created a crystal report with the report.rpt reportdata.xsd I created the a new dataset with the reportdata myreportdata = new reportdata(); That automatically created a new dataset with all the fields I
1
7766
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a label and hours, along with an edit linkbutton. When they click on edit, the edit button turns to Update Cancel TimeID stays read Only
13
10792
by: Tomasz Jastrzebski | last post by:
Helo All, The problem: GridView control does not render at all (header/footer) when the data source is empty. I have seen a similar question posted already, but I just can not believe there is no simple solution. I do not believe ASP.Net team took this, sort of, innovative approach and left no way out. Could anybody advise?
2
6735
by: Wayne Deleer | last post by:
Hi All, I'm currently working on a project, and I've come to a part where I want to add data to a GridView. BUT, I want to do it programmatically, with alot of control over everything. In my particular project I've passed a DataSet to a page via a Session object. The Session object passes without incident, and I can use the default settings to retrieve the information without problem and plug all the information into the GridView.
0
1969
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" Height="237px" Style="z-index: 100; left: 155px; position: absolute; top: 132px" Width="688px" BackColor="White" BorderColor="#CCCCCC"...
2
3122
by: Kbalz | last post by:
I have a user control that has a gridview in it. I am dynamically setting up its datasource and columns based on an XML file. I have everything done except adding columns to the gridview, so that the user only sees certain columns based on the XML file. In my ASCX page I simply defined the gridview <asp:GridView ID="gvSearchResults" HorizontalAlign="Center" AllowSorting="true" runat="server"
3
2185
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a gridview that uses a sqldatasource. The rows of the gridview are editable. When the gridview is in edit mode, one of the columns is a dropdown. In testing the editing, I deleted the dropdown entry from one of the rows. So, when the gridview comes up, it shows nothing in the column where I deleted it. Then when I select to edit that same row, I get an error because I cannot select the value for the dropdown for a non-existing value....
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.