Solved

Help with retreiving data and appending data in gridview

Posted on 2012-04-03
13
302 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
  • 9
  • 4
13 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the links, unfortunately I'm using XML with a thirdparty Grid from ComponentOne, but the informations was very useful.
0
 
LVL 83

Accepted Solution

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

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Can you show the code you are using?
0
 

Author Comment

by:vcharles
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

13 Experts available now in Live!

Get 1:1 Help Now