Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with retreiving data and appending data in gridview

Posted on 2012-04-03
13
Medium Priority
?
313 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

783 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