添加Gridview行

时间:2015-11-03 20:37:49

标签: vb.net gridview oracle10g row

在引用How to add gridview rows to a datatable?时,我尝试基于数组创建网格视图。

到目前为止,我的数组[ email_list ]包含字符串,其中每个索引都有 3个以| 分隔的字符串。

示例:

Index1:1231|Apple Company|apple@yahoo.com

Index2:141411|KFC|eatChicken@yahoo.com

要分隔字符串,我会执行以下操作[确实有用]

 Dim strarray2() As String = email_list(i).Split("|"c)

  For Each str2 In strarray2
    Dim r As String = ""
    r = strarray2(y)
    y = y + 1
  Next

 ID = strarray2(0)
 company = strarray2(1)
 email = strarray2(2)

我想要的是什么:

每次循环遍历email_list数组时,我想填充gridview。

问题:

截至目前,字符串分为3个变量:ID, company, email我调试了字符串,实际上它们确实有效。

然而;将值添加到gridview后,gridview不会填充[aka notn tt up up on page]。这告诉我,添加新行的方式是错误的。

我尝试过:

For Each row As GridViewRow In DisplaySup.Rows
   If row.RowType = DataControlRowType.DataRow Then

在我的编码之外但由于目前没有行,我的所有编码都没有执行所以我把它拿出来。

有关如何修改以下编码的任何建议?

VB.NET

Dim dt As DataTable = New DataTable()

   dt.Columns.Add(New DataColumn("ID", GetType(String)))
   dt.Columns.Add(New DataColumn("Company Name", GetType(String)))
   dt.Columns.Add(New DataColumn("Email", GetType(String)))

        For i As Integer = 0 To email_list.Length - 2

            Dim y As Integer = 0
            Dim strarray2() As String = email_list(i).Split("|"c)

            For Each str2 In strarray2
                Dim r As String = ""
                r = strarray2(y)
                y = y + 1
            Next

            ID = strarray2(0)
            company = strarray2(1)
            email = strarray2(2)

            'ADD ONE ROW AT A TIME [my logic of what I want]
            Dim dr As DataRow = dt.NewRow()
            dr("ID") = Convert.ToString(ID)
            dr("Company Name") = Convert.ToString(company)
            dr("Email") = Convert.ToString(email)
            dt.Rows.Add(dr)

      Next

HTML:

<asp:GridView ID="DisplaySup" runat="server" align="center" 
Width="99%" AutoGenerateColumns="False"
BorderColor="Black" BorderStyle="Solid" DataKeyNames="ID" 
cssClass="grid_padding4" Font-Size="XX-Small">
   <Columns>

       <asp:BoundField DataField="ID" HeaderText="ID"> 
       <ItemStyle cssClass="grid_padding" width="15px"/>
       </asp:BoundField>

       <asp:BoundField DataField="company" HeaderText="Company Name" > 
       <ItemStyle cssClass="grid_padding" width="125px"/>
       </asp:BoundField>

       <asp:BoundField DataField="email" HeaderText="Owner Email" > 
       <ItemStyle cssClass="grid_padding" width="50px"/>
       </asp:BoundField>

    </Columns>

    <HeaderStyle BackColor="#BDBDAE" Font-Underline="False" 
       CssClass="linkNoUnderline" HorizontalAlign="Left" />
    <SelectedRowStyle BackColor="#99CCFF" />
</asp:GridView>

2 个答案:

答案 0 :(得分:1)

您已创建clang -framework OpenGL -framework GLUT ,但您已将其分配给DataTable了吗?检查代码中的所有注释

GridView

答案 1 :(得分:0)

不确定为什么要打扰数据表。下面是一些在未绑定的DataGridView(dgv1)中显示数组的代码。它不会更改数组内容,所以您可能希望使用数据表进行更新?

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
    ' overhead for my testing
    Dim sData() As String = {"1231|Apple Company|apple@yahoo.com", "141411|KFC|eatChicken@yahoo.com"}
    dgv1.DataSource = Nothing

    ' could be done in designer one time
    dgv1.Columns.Clear()
    dgv1.Columns.Add("ID", "ID")
    dgv1.Columns.Add("Company", "Company")
    dgv1.Columns.Add("URL", "URL")

    For Each s As String In sData
        dgv1.Rows.Add(s.Split("|"))
    Next
    dgv1.AutoResizeColumns()
    dgv1.ClearSelection()
End Sub