?
Solved

Why is there duplicate columns on my gridview? Please help

Posted on 2012-03-31
2
Medium Priority
?
3,367 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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