Solved

Help with retreiving data and appending data in gridview

Posted on 2012-04-03
13
304 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

937 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

7 Experts available now in Live!

Get 1:1 Help Now