Solved

Why is there duplicate columns on my gridview? Please help

Posted on 2012-03-31
2
3,188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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