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. - private void GridViewFunktion()
-
{
-
-
DataColumn colOrigName = new DataColumn("Original_Name");
-
DataColumn colNr = new DataColumn("Nr");
-
DataColumn colSystem_Hop = new DataColumn("System_Hop");
-
DataColumn colType = new DataColumn("Type");
-
-
-
myTable.Columns.Add(colOrigName);
-
myTable.Columns.Add(colNr);
-
myTable.Columns.Add(colSystem_Hop);
-
myTable.Columns.Add(colType);
-
-
varStringedt = OtherFunktions.VARSTRINGEDT;
-
-
for (int i = 0; i < varStringedt.Length; i++)
-
{
-
DataRow myRow;
-
myRow = myTable.NewRow();
-
myRow["Original_Name"] = varStringedt[i];
-
-
-
myTable.Rows.Add(myRow);
-
}
-
-
ReMk1_SE_dataGridView.DataSource = myTable;
-
}
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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
|
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
|
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?
| |
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.
|
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"...
|
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"
|
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....
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |