Solved

Help with retreiving data and appending data in gridview

Posted on 2012-04-03
13
308 Views
Last Modified: 2012-04-30
Hello,

I am loading my Grid with 4 rows of the following data from an XML file

1-
2-
3-
4-

If users only enter data in the first two rows for example

1-Data 1
2-Data 2

How do I only loop through the first two rows, and pass their data in the following format

1-Data1; 2-Data2

to a textbox?

And if the user deicdes to enter more rows, How do I add news rows to add more data?


Afterwards, when I load the grid to update data, How do I display the data back in the grid
in ther following format:

1-Data 1
2-Data 2

(After it was saved in the folowing format: 1-Data1; 2-Data2)
 

Victor
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
13 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37805302
Too many questions in a single post.

>How do I only loop through the first two rows, and pass their data in the following format

Loop through all the rows but only do appending if the cell is not empty. Use String.IsNullOrEmpty

>And if the user deicdes to enter more rows, How do I add news rows to add more data?
Use the Footer template to add rows.
http://www.dotnetfunda.com/articles/article180.aspx
http://www.aspdotnetfaq.com/Faq/How-to-insert-row-in-GridView-with-SqlDataSource.aspx

>Afterwards, when I load the grid to update data, How do I display the data back in the grid
in ther following format:

As suggested in your other question. Split the string and add rows.
0
 

Author Comment

by:vcharles
ID: 37806355
Hi,

Can you please help me with a sample code for the following:

Loop through all the rows but only do appending if the cell is not empty. Use String.IsNullOrEmpty

Victor
0
 

Author Comment

by:vcharles
ID: 37806422
Thanks for the links, unfortunately I'm using XML with a thirdparty Grid from ComponentOne, but the informations was very useful.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37807692
Have you managed to loop through the row and get cell text?
0
 

Author Comment

by:vcharles
ID: 37808005
Hi,

I know I did this before but I can't seem to find the code,can you please send me the code that loops through the Grid, will be sure not to lose it this time.
Thanks.
0
 

Author Comment

by:vcharles
ID: 37809840
Can you please help me finish the syntax to retreive the data from the Grid.
The code in part A works for the Listbox, but for the Grid, Items is not a property, what is the correct syntax to use?          

Part A:
   For x = 0 To ListBox1.Items.Count - 1
   C1NSN.Text = If(String.IsNullOrEmpty(C1NSN.Text.ToString.Trim), ListBox1.Items(x).Text, C1NSN.Text & ";" & ListBox1.Items(x).Text)
    Next

Part B:

        For x As Integer = 0 To C1GridView1.Rows.Count - 1
            C1NSN.Text = If(String.IsNullOrEmpty(C1NSN.Text.ToString.Trim), C1GridView1.Items(x).Text, C1NSN.Text & ";" & C1GridView1.Items(x).Text)
        Next
0
 

Author Comment

by:vcharles
ID: 37809914
OK, I am getting closer focusing on the regular Grid. I managed to loop through the Gridview and pass its data to a textbox using the code below:

   For x As Integer = 0 To GridView1.Rows.Count - 1
            C1NSN.Text = If(String.IsNullOrEmpty(C1NSN.Text.ToString.Trim), GridView1.Rows(x).Cells(0).Text, C1NSN.Text & ";" & GridView1.Rows(x).Cells(0).Text)
        Next

How do I set the Grid to editable, I don't see an edit property?
0
 

Author Comment

by:vcharles
ID: 37810175
Hello again,

Just noticed a problem. Eventhough I entered text in the first two rows of the Grid, when I try to move the data to the textbox, it still shows as the initial display shown below:

1-
2-
3-
4-

When I enter the following:

1- Data 1
2- Data 2
3-
4-

I would only like to see Data 1;Data 2 in my textbox.

How do I fix this problem?
0
 

Author Comment

by:vcharles
ID: 37810192
Just two be clear, I am testing with the third party Grid, until I am able to edit data in the regular Grid, but I suspect the same issue will occur with the regular Grid.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37810463
Right. So now you have managed to loop? And you are unable to see the new data entered on grid?
0
 

Author Comment

by:vcharles
ID: 37810692
Yes,  for some reason the data I typed in the grid does not appear in the textbox only the
initial data below it was initially loaded with. I looked for a postback property but it doesn't exist.

1-
2-
3-
4-
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37811962
Can you show the code you are using?
0
 

Author Comment

by:vcharles
ID: 37812286
I am using the following code:

1. Form Load event:

            C1NSN.Text = "1.;2.;3.;4.;5."
            Dim tmp() As String = C1NSN.Text.Split(";")
            Dim dTable As New DataTable
            dTable.Columns.Add("Column1", GetType(String))
            For i As Integer = 0 To tmp.Length - 1
                dTable.Rows.Add(New Object() {tmp(i)})
            Next
            C1GridView1.DataSource = dTable
            C1GridView1.DataBind()        

2. Button Click event to transfer data from Grid to Textbox.

 For x As Integer = 0 To C1GridView1.Rows.Count - 1
            C1NSN.Text = If(String.IsNullOrEmpty(C1NSN.Text.ToString.Trim), C1GridView1.Rows(x).Cells(0).Text, C1NSN.Text & ";" & C1GridView1.Rows(x).Cells(0).Text)
        Next
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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