Solved

Why is there duplicate columns on my gridview? Please help

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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