Solved

Help with retreiving data and appending data in gridview

Posted on 2012-04-03
13
307 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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