1 Replies - 1110 Views - Last Post: 06 July 2014 - 10:38 PM Rate Topic: -----

#1 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 82
  • Joined: 14-December 13

GridView Duplicating

Posted 06 July 2014 - 10:21 PM

I am trying to figure out why my columns in Gridview show up twice for each column. I am using VS 2012 and its an ASP.NET project and SQL Server 2012. Here is the aspx page:

  <asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:BoundField DataField="ClientFirstName" HeaderText="First Name" />
            <asp:BoundField DataField="ClientLastName" HeaderText="Last Name" />
            <asp:BoundField DataField="MagazineName" HeaderText="Magazine" />
            <asp:BoundField DataField="Price" DataFormatString="{0:c}" HeaderText="Price" />
            <asp:BoundField DataField="StartDate" DataFormatString="{0:d}" HeaderText="Start Date" />
            <asp:BoundField DataField="EndDate" DataFormatString="{0:d}" HeaderText="End Date" />
        </Columns>
    </asp:GridView>



And here is the code behind:

 protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.DataSource = RefreshSubscriptionGrid();
            GridView1.DataBind();
        }

        private DataSet RefreshSubscriptionGrid()
        {
            DataSet ds = new DataSet();
            SqlConnection conn = new SqlConnection(@"Data Source=localhost;Initial Catalog=dbExercise641;Integrated Security=SSPI");
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand("spGetSubscriptionTable", conn);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            conn.Open();
            da.Fill(ds);
            conn.Close();
            return ds;
        }



Finally, the SQL:

GO
CREATE PROCEDURE spGetSubscriptionTable
AS
BEGIN
	select ClientFirstName, ClientLastName, MagazineName, Price, StartDate, EndDate
	from tbClient
	inner join tbSubscription on
	tbSubscription.SubscriberID=tbClient.ClientID
	inner join tbMagazine on
	tbSubscription.MagazineID=tbMagazine.MagazineID	
END




Is This A Good Question/Topic? 0
  • +

Replies To: GridView Duplicating

#2 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 82
  • Joined: 14-December 13

Re: GridView Duplicating

Posted 06 July 2014 - 10:38 PM

I think I figured it out. I forgot to uncheck the 'auto-generate columns' check box. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1