Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to pass data from Listbox and Grid to a textbox

Posted on 2012-04-04
11
Medium Priority
?
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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