Solved

Why is there duplicate columns on my gridview? Please help

Posted on 2012-03-31
2
2,836 Views
Last Modified: 2012-03-31
Hi all I have the following gridview in my aspx page

 <asp:GridView ID="GridView1" runat="server">
        <Columns>
        <asp:BoundField DataField="RName" HeaderText="Row Number" />
        <asp:BoundField DataField="RContact" HeaderText="Row Number" />
        <asp:BoundField DataField="RPostalCode" HeaderText="Row Number" />
        <asp:BoundField DataField="RAddress" HeaderText="Row Number" />
        <asp:BoundField DataField="RUnitNo" HeaderText="Row Number" />
        <asp:BoundField DataField="Size" HeaderText="Row Number" />
        <asp:BoundField DataField="Weight" HeaderText="Row Number" />
        <asp:BoundField DataField="Price" HeaderText="Row Number" />

        <asp:TemplateField HeaderText="Action">
            <ItemTemplate>
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </ItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>


I have the following datatable that bind to it in the code behind

Dim dt As New DataTable()

        dt.Columns.Add(New DataColumn("RName", GetType(String)))
        dt.Columns.Add(New DataColumn("RContact", GetType(String)))
        dt.Columns.Add(New DataColumn("RPostalCode", GetType(String)))
        dt.Columns.Add(New DataColumn("RAddress", GetType(String)))
        dt.Columns.Add(New DataColumn("RUnitNo", GetType(String)))
        dt.Columns.Add(New DataColumn("Size", GetType(String)))
        dt.Columns.Add(New DataColumn("Weight", GetType(String)))
        dt.Columns.Add(New DataColumn("Price", GetType(String)))
     
        Dim dr As DataRow = dt.NewRow()

        dr("RName") = txtRecipientName.Text
        dr("RContact") = txtRecipientContact.Text
        dr("RPostalCode") = txtRecipientPostalCode.Text
        dr("RAddress") = txtRecipientAddress.Text
        dr("RUnitNo") = txtRecipientUnitNo.Text
        dr("Size") = txtSize.Text
        dr("Weight") = txtWeight.Text
        dr("Price") = MainModule.CalculateRate(txtWeight.Text, txtSize.Text)
        dt.Rows.Add(dr)
     

        GridView1.Visible = True

        GridView1.DataSource = dt

        GridView1.DataBind()


The problem is that my gridview will have duplicate column and data e.g

Example after populating gridview
0
Comment
Question by:leechoonhwee
2 Comments
 
LVL 5

Accepted Solution

by:
Aruiz04 earned 500 total points
ID: 37791423
on this line
 <asp:GridView ID="GridView1" runat="server">
add tag "autogeneratecolumns=false"

 <asp:GridView ID="GridView1" runat="server" autogeneratecolumns = false>
0
 
LVL 9

Author Closing Comment

by:leechoonhwee
ID: 37791471
Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now