Solved

How to pass data from Listbox and Grid to a textbox

Posted on 2012-04-04
11
441 Views
Last Modified: 2012-04-30
Hello,

I am using the code below to pass the data from my textbox to multiple rows of my listbox.

C1NSN.Text = dtNSN.Rows(0).Item("NSN")
        Dim tmp() As String = C1NSN.Text.split(";")
        For i As Integer = 0 To tmp.Length - 1
            'ListBox1.Items.Add(tmp(i))
             GridView1.??????
        Next


How do I also pass it to a Gridview?

Victor
0
Comment
Question by:vcharles
  • 7
  • 3
11 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37805574
Do:
GridView1.Rows.Add(tmp(i))

Open in new window

0
 

Author Comment

by:vcharles
ID: 37806178
I tried it with the regular Gridview that comes with VS and received the following error:

"Add is not a member of  System.We.UI.Webcontrols.GridViewRowCollection"

When I treid the Gridview from ComponentOne, I received the following error:

"Is not accessible in this content because it is Friend"

Any ideas how to fix this problem?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37807635
You can use a DataTable, fill it and then set it as datasource of grid.

C1NSN.Text = dtNSN.Rows(0).Item("NSN")
        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
            'ListBox1.Items.Add(tmp(i))
             dTable.Rows.Add(new object() { tmp(i) })
        Next
        Gridview1.DataSource = dTable
        Gridview1.Databind()

Open in new window

0
 

Author Comment

by:vcharles
ID: 37807767
That is a great idea. I will try it and get back to you.
Thanks.
0
 

Author Comment

by:vcharles
ID: 37807940
It worked, but I got the following error when using the code with my third party control.

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

The error ocurrs on this function:

   function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) {
        if (this._request === executor.get_webRequest()) {
            this._processingRequest = false;
            this._additionalInput = null;
            this._request = null;
        }
        var handler = this._get_eventHandlerList().getHandler("endRequest");
        var errorHandled = false;
        if (handler) {
            var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
            handler(this, eventArgs);
            errorHandled = eventArgs.get_errorHandled();
        }
        if (error && !errorHandled) {
            throw error; 'Error********************
        }
    }

When I used the regular Grid, it worked but I am unable to edit data and I don't see a property to the edit property. How do I set the edit property to true and How do I remove the column header.

Any ideas why I am getting the error with the third party control?

Thanks.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:vcharles
ID: 37808131
Just realised I can use a string rather than a textbox, below is my latest code, but I still have the same issues mentioned in the previous post.
           Dim s as string
           s = "1.;2.;3.;4.;5."
            Dim tmp() As String = s.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
            GridView1.DataSource = dTable
            GridView1.DataBind()
            GridView1.Caption = False
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37810492
No idea why would you get that error. So the data displays as expected when using a standard grid? That means there is no problem with the above code.
0
 

Author Comment

by:vcharles
ID: 37810681
Using the regular Grid, how do you set the Grid to edit mode, and as mentioned in a nother post I ran into other issues with passing the data to a textbox.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37811965
For Gridview, you need to set the edititemindex of the grid and you can only edit one row at a time? Do you want to go that route?
0
 

Author Comment

by:vcharles
ID: 37812131
Yes. I will enter the data and see if I can pass it to a text box. Thanks.
0
 

Author Comment

by:vcharles
ID: 37812241
I tried GridView1.EditIndex = True but still unable to add data in the rows.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

18 Experts available now in Live!

Get 1:1 Help Now