但是我想要它添加两个项目

但是我想要它添加两个项目

本文介绍了Gridview只添加一个项目。但是我想要它添加两个项目。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的listbox2项是需要添加为列的项目。我正在使用一个按钮将列表框1中的项目添加到列表框2.因此,如果将listbox1项目x,y坐标添加到listbox2项目,那么我需要将列x,y坐标添加到gridview。如果listbox1项目纬度,经度被添加到listbox2然后我需要将列纬度,经度添加到gridview。但是,如果两个项目都从列表框1添加到列表框2,那么我想显示下面有行的列。代码如下:但是,我想添加在一个页面上选择的列表框,然后在另一个页面的网格视图中显示它。因此,我创建了一个全局变量类,它从listbox2.items.text中获取文本项并按如下所述添加它:



My listbox2 items are the items needed to be added as columns. i am using a button to add items from listbox1 to listbox 2. so lets say if listbox1 item x,y coordinate is added to listbox2 item then i need to add column x,y coordinate to the gridview. if listbox1 item latitude, longitude is added to listbox2 then i need to add column latitude, longitude to the gridview. however, if both of the items are added to listbox 2 from listbox 1 then i want to show both columns with rows underneath. the code is below: However, i want to add the listboxes selected on one page and then display it in a grid view on another page. Therefore i created a global variable class which takes the text item from the listbox2.items.text and adds it as explained below:

Dim dt As New DataTable
    dt.Clear()
                For i As Integer = 0 To GlobalVariable.listbox2Count - 1
                    If GlobalVariable.containsListBox2Item = "X,Y Coordinate" Then
                        dt.Columns.Add("X Coordinate")
                        dt.Columns.Add("Y Coordinate")
                    ElseIf GlobalVariable.containsListBox2Item = "Latitude, Longitude" Then
                        dt.Columns.Add("Latitude")
                        dt.Columns.Add("Longitude")
                    End If
                Next
                Dim mr As DataRow
                mr = dt.NewRow
                If dt.Columns.Contains("X Coordinate") Then
                    mr("X Coordinate") = "100252"
                    mr("Y Coordinate") = "215120"
                Else
                    mr("Latitude") = "202030"
                    mr("Longitude") = "515123"
                End If
                dt.Rows.Add(mr)
                GridView1.DataSource = dt
                GridView1.DataBind()





我的gridview页面的模型如下:





My mockup for the gridview page is below:

<asp:GridView ID="GridView1" AutoGenerateColumns="true" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>





我的公开课程如下:





My Public Class is Below:

public class GlobalVariable
        public shared listbox2Count = listbox2.items.count
        public shared containsListbox2Item
End Class





我的代码,我将文本项分配给变量对象:





my code where i assign a text item to a variable object:

Public Function getListBoxText()

If ListBox2.Text = "X,Y Coordinate" Then
    GlobalVariable.containsListBox2Item = "X,Y Coordinate"
ElseIf ListBox2.Text = "Latitude, Longitude" Then
    GlobalVariable.containsListBox2Item = "Latitude, Longitude"
Return Nothing
End Function







我尝试了什么:



i尝试谷歌搜索和调试对接断点,但只有一个项目添加。




What I have tried:

i tried googling and debugging butting break points but only one item adds.

推荐答案


这篇关于Gridview只添加一个项目。但是我想要它添加两个项目。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 17:01