Solved

How to pass data from Listbox and Grid to a textbox

Posted on 2012-04-04
11
446 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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.…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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