Link to home
Start Free TrialLog in
Avatar of HawaiiDragon
HawaiiDragon

asked on

Populate a gridview from a stored proc

I havent done this one in a while ... .I have a gridview that I need to populate from a stored procedure below is both my code and the stored proc code. I am geting an erro that states:

Both DataSource and DataSourceID are defined on 'GridView1'.  Remove one definition.

help!!!
protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(Settings.GetConfigValue("PARK_GradeAppeal_v1", "GradeAppealSuperConnections"));
            con.Open();
            SqlCommand cmd = new SqlCommand("P_sp_GetAdmin", con);

            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader sdr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(sdr);
            GridView1.DataSource = dt;
            GridView1.DataBind();


        }

Open in new window

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
alter PROCEDURE [dbo].[P_sp_GetAdmin]
	-- Add the parameters for the stored procedure here

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT * from tbl_AdminUsers

END

Open in new window

SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HawaiiDragon
HawaiiDragon

ASKER

@jacko72

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
    EnableModelValidation="True">
</asp:GridView>
ha ha hah I removed the Datasource ID and got rid of the problem eveyone gets free points!!!!

I feel retarded LOL