Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code Below which i am confused on:

Public Class WebForm3<br />
        Inherits System.Web.UI.Page<br />
<br />
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />
<br />
            Dim dt As New DataTable<br />
            If GlobalVariable.containsListBox2Item = "X,Y Coordinate" Then<br />
                dt.Columns.Add("X Coordinate")<br />
                dt.Columns.Add("Y Coordinate")<br />
                Dim mr As DataRow<br />
                mr = dt.NewRow<br />
                mr("X Coordinate") = "909090"<br />
                mr("Y Coordinate") = "109209"<br />
                dt.Rows.Add(mr)<br />
                GridView1.DataSource = dt<br />
            End If<br />
            If GlobalVariable.containsListBox2Item = "Latitude, Longitude" Then<br />
                dt.Columns.Add("Latitude")<br />
                dt.Columns.Add("Longitude")<br />
                Dim mr As DataRow<br />
                mr = dt.NewRow<br />
                mr("Latitude") = "100909"<br />
                mr("Longitude") = "1002929"<br />
                dt.Rows.Add(mr)<br />
                GridView1.DataSource = dt<br />
            End If<br />
            GridView1.DataBind()<br />
<br />
        End Sub



Basically what i want to do is if one item from another page is clicked it is stored in the GlobalVariable class. Therefore, if both of these items X,Y Coordinate and Latitude, Longitude are clicked i want to display both. Not just one item. but 4 columns with data. I think i am coding wrong. Please Help. Thanks

What I have tried:

Basically did as much as my college knowledge permits me to do. Please Help Urgent.
Posted
Updated 3-May-16 20:22pm

1 solution

Yes, you're doing it wrong. Change containsListBox2Item with concatenated string to string collection, NameValue pairs, List (Of String) or some other kind of list in which you can add multiple things.

Then, instead of checking if your variable contains the string (in which you depend on spaces after comma for equality (X,Y Coordinate - no space after comma; Latitude, Longitude - space after comma) and order of the text and maybe case (if not case insensitive) ), you loop through your collection and add columns to your datatable directly from the collection.

Good luck.

P.S: saying that this is urgent will not make it so for others. And your knowledge should not be limited by the knowledge imparted by the university. Read up, there is Coursera, Microsoft Virtual Academy, Code Project Articles and many other sources of knowledge.
 
Share this answer
 
Comments
JT1992 4-May-16 10:49am    
how would i be able to do that? is there a code sample i can use? or maybe you can help me code this issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900