3 Replies - 3202 Views - Last Post: 01 November 2010 - 04:09 PM Rate Topic: -----

#1 Kaustix  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 03-November 09

Creating Dynamic GridView

Posted 31 October 2010 - 02:16 PM

Hi, i'm trying to create a dynamic gridview but i seem to keep getting doubles(Same gridview twice side by side), not sure whats wrong with my code

Dim GridView1 As New GridView
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim DBPath As String = Server.MapPath("~/App_Data/CalanderDays.accdb")
        Dim ConnectionString As String = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath
        Dim SqlString As String = "SELECT * FROM Days"
        Dim Con As New OleDbConnection(ConnectionString)
        Dim Cmd As New OleDbCommand(SqlString, Con)
        Dim da As New OleDbDataAdapter(Cmd)
        Dim ds As New DataSet
        Try
            Cmd.Connection.Open()
            da.Fill(ds)
        Catch ex As Exception
        Finally
            Con.Close()
        End Try
        Dim dc As DataColumn
        If ds.Tables.Count > 0 Then
            For Each dc In ds.Tables(0).Columns
                Dim bField As New BoundField
                bField.DataField = dc.ColumnName
                bField.HeaderText = dc.ColumnName
                GridView1.Columns.Add(bField)
            Next
        End If
        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()
        Me.Controls.Add(GridView1)
        Me.Controls.Add(New LiteralControl("<br>"))
    End Sub

This post has been edited by Kaustix: 31 October 2010 - 02:20 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Creating Dynamic GridView

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Creating Dynamic GridView

Posted 31 October 2010 - 08:58 PM

Can you post the source for the page?

Do you have a GridView defined there as well as in the code-behind?
Was This Post Helpful? 0
  • +
  • -

#3 Kaustix  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 03-November 09

Re: Creating Dynamic GridView

Posted 01 November 2010 - 11:35 AM

In the code is the only time i create the gridview, from what i see its only 1 gridview but im getting duplicate headers and rows
heres the html code...


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Calander.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
    <asp:Label ID="Label1" runat="server" Text="Date"></asp:Label>
    <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="Label2" runat="server" Text="Message"></asp:Label>
    <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox>
    <br />
    <asp:Label ID="Label3" runat="server" Text="Color"></asp:Label>
    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem>Red</asp:ListItem>
        <asp:ListItem>Green</asp:ListItem>
        <asp:ListItem>Blue</asp:ListItem>
        <asp:ListItem>Yellow</asp:ListItem>
        <asp:ListItem>Orange</asp:ListItem>
        <asp:ListItem>Purple</asp:ListItem>
        <asp:ListItem>Pink</asp:ListItem>
        <asp:ListItem>Black</asp:ListItem>
    </asp:DropDownList>
    <p>
        <asp:Button ID="btnSave" runat="server" Text="Save" Width="184px" />
    </p>
    </form>
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

#4 Kaustix  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 03-November 09

Re: Creating Dynamic GridView

Posted 01 November 2010 - 04:09 PM

figured this one out, removed the loop and it all worked ><
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1