Solved

Why is there duplicate columns on my gridview? Please help

Posted on 2012-03-31
2
2,929 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

13 Experts available now in Live!

Get 1:1 Help Now