[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to pass data from Listbox and Grid to a textbox

Posted on 2012-04-04
11
Medium Priority
?
452 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 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
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…
Loops Section Overview
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 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