hi iam gettin error like........
"The DataSourceID of 'gridview1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource' could not be found."
here my coding is given below..........

<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource" DataKeyNames="gp_no" ShowFooter="true" >
            <Columns>
                <asp:TemplateField HeaderText="gp_no">
                    <ItemTemplate>
                        <%#Eval("gp_no")%>  
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="year">
                    <ItemTemplate>
                    <%# Eval("year") %> 
                    </ItemTemplate>
                     <FooterTemplate>
                        <asp:TextBox runat="server" ID="year" Text='<%# Bind("year") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                <asp:TemplateField HeaderText="sno">
                    <ItemTemplate>
                    <%# Eval("sno") %> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="sno" Text='<%# Bind("sno") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="description">
                    <ItemTemplate>
                    <%#Eval("description")%> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="description" Text='<%# Bind("description") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="make">
                    <ItemTemplate>
                    <%#Eval("make")%> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="make" Text='<%# Bind("make") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="equip_no">
                    <ItemTemplate>
                    <%#Eval("equip_no")%> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="equip_no" Text='<%# Bind("equip_no") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
 <asp:TemplateField>
                   <FooterTemplate>
                    <asp:Button runat="server" ID="Insert" Text="Insert" CommandName="InsertNew" />                
                    <asp:Button runat="server" ID="Cancel" Text="Cancel" CommandName="CancelNew" />                                    
                </FooterTemplate>
                </asp:TemplateField>
            </Columns>
            <EmptyDataTemplate>
                <asp:TextBox ID="TextBox1" runat="server"  />
                <asp:TextBox ID="TextBox2" runat="server"  />
                <asp:Button runat="server" ID="NoDataInsert" CommandName="NoDataInsert" Text="Insert"/>
            </EmptyDataTemplate>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:guest2 %>"
            SelectCommand="SELECT [gp_no], [year], [sno], [description], [make], [equip_no] FROM [gatein_item]"
            InsertCommand="Insert into Customers (gp_no, year, sno,description,make,equip_no,qty,total_packets) values (@gp_no, @year, @sno,@description,@make,@equip_no,@qty,@total_packets)"
         OnInserting="Sqldatasource1_Inserting">
        </asp:SqlDataSource>
       


Imports System
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Partial Class guest
    Inherits System.Web.UI.Page
    Private insertParameters As New List(Of SqlParameter)()


    Protected Sub gridview1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
        If e.CommandName = "InsertNew" Then
            Dim year As TextBox = TryCast(gridview1.FooterRow.FindControl("year"), TextBox)
            Dim sno As TextBox = TryCast(gridview1.FooterRow.FindControl("sno"), TextBox)
            Dim description As TextBox = TryCast(gridview1.FooterRow.FindControl("description"), TextBox)
            Dim make As TextBox = TryCast(gridview1.FooterRow.FindControl("make"), TextBox)
            Dim equip_no As TextBox = TryCast(gridview1.FooterRow.FindControl("equip_no"), TextBox)

            Dim fyear As New SqlParameter("@year", SqlDbType.VarChar, 30)
            fyear.Direction = ParameterDirection.Input
            fyear.Value = year.Text
            insertParameters.Add(fyear)
            Dim fsno As New SqlParameter("@sno", SqlDbType.Int, 30)
            fsno.Direction = ParameterDirection.Input
            fsno.Value = sno.Text
            insertParameters.Add(fyear)
            Dim fdescription As New SqlParameter("@description", SqlDbType.VarChar, 30)
            fdescription.Direction = ParameterDirection.Input
            fdescription.Value = description.Text
            insertParameters.Add(fyear)
            Dim fmake As New SqlParameter("@make", SqlDbType.VarChar, 30)
            fmake.Direction = ParameterDirection.Input
            fmake.Value = make.Text
            insertParameters.Add(fyear)
            Dim fequip_no As New SqlParameter("@equip_no", SqlDbType.VarChar, 30)
            fequip_no.Direction = ParameterDirection.Input
            fequip_no.Value = equip_no.Text
            insertParameters.Add(fyear)

            insertParameters.Add(fyear)
            insertParameters.Add(fsno)
            insertParameters.Add(fdescription)
            insertParameters.Add(fmake)
            insertParameters.Add(fequip_no)
            SqlDataSource1.Insert()

        End If
    End Sub
    Protected Sub Sqldatasource1_Inserting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs)
        e.Command.Parameters.Clear()
        For Each p As SqlParameter In insertParameters
            e.Command.Parameters.Add(p)
        Next
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
End Class

hi iam gettin error like........
"The DataSourceID of 'gridview1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource' could not be found."
here my coding is given below..........

<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource" DataKeyNames="gp_no" ShowFooter="true" >
            <Columns>
                <asp:TemplateField HeaderText="gp_no">
                    <ItemTemplate>
                        <%#Eval("gp_no")%>  
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="year">
                    <ItemTemplate>
                    <%# Eval("year") %> 
                    </ItemTemplate>
                     <FooterTemplate>
                        <asp:TextBox runat="server" ID="year" Text='<%# Bind("year") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                <asp:TemplateField HeaderText="sno">
                    <ItemTemplate>
                    <%# Eval("sno") %> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="sno" Text='<%# Bind("sno") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="description">
                    <ItemTemplate>
                    <%#Eval("description")%> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="description" Text='<%# Bind("description") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="make">
                    <ItemTemplate>
                    <%#Eval("make")%> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="make" Text='<%# Bind("make") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="equip_no">
                    <ItemTemplate>
                    <%#Eval("equip_no")%> 
                    </ItemTemplate>
                <FooterTemplate>
                        <asp:TextBox runat="server" ID="equip_no" Text='<%# Bind("equip_no") %>' />                    
                    </FooterTemplate>                        
                </asp:TemplateField>
 <asp:TemplateField>
                   <FooterTemplate>
                    <asp:Button runat="server" ID="Insert" Text="Insert" CommandName="InsertNew" />                
                    <asp:Button runat="server" ID="Cancel" Text="Cancel" CommandName="CancelNew" />                                    
                </FooterTemplate>
                </asp:TemplateField>
            </Columns>
            <EmptyDataTemplate>
                <asp:TextBox ID="TextBox1" runat="server"  />
                <asp:TextBox ID="TextBox2" runat="server"  />
                <asp:Button runat="server" ID="NoDataInsert" CommandName="NoDataInsert" Text="Insert"/>
            </EmptyDataTemplate>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:guest2 %>"
            SelectCommand="SELECT [gp_no], [year], [sno], [description], [make], [equip_no] FROM [gatein_item]"
            InsertCommand="Insert into Customers (gp_no, year, sno,description,make,equip_no,qty,total_packets) values (@gp_no, @year, @sno,@description,@make,@equip_no,@qty,@total_packets)"
         OnInserting="Sqldatasource1_Inserting">
        </asp:SqlDataSource>
       


Imports System
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Partial Class guest
    Inherits System.Web.UI.Page
    Private insertParameters As New List(Of SqlParameter)()


    Protected Sub gridview1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
        If e.CommandName = "InsertNew" Then
            Dim year As TextBox = TryCast(gridview1.FooterRow.FindControl("year"), TextBox)
            Dim sno As TextBox = TryCast(gridview1.FooterRow.FindControl("sno"), TextBox)
            Dim description As TextBox = TryCast(gridview1.FooterRow.FindControl("description"), TextBox)
            Dim make As TextBox = TryCast(gridview1.FooterRow.FindControl("make"), TextBox)
            Dim equip_no As TextBox = TryCast(gridview1.FooterRow.FindControl("equip_no"), TextBox)

            Dim fyear As New SqlParameter("@year", SqlDbType.VarChar, 30)
            fyear.Direction = ParameterDirection.Input
            fyear.Value = year.Text
            insertParameters.Add(fyear)
            Dim fsno As New SqlParameter("@sno", SqlDbType.Int, 30)
            fsno.Direction = ParameterDirection.Input
            fsno.Value = sno.Text
            insertParameters.Add(fyear)
            Dim fdescription As New SqlParameter("@description", SqlDbType.VarChar, 30)
            fdescription.Direction = ParameterDirection.Input
            fdescription.Value = description.Text
            insertParameters.Add(fyear)
            Dim fmake As New SqlParameter("@make", SqlDbType.VarChar, 30)
            fmake.Direction = ParameterDirection.Input
            fmake.Value = make.Text
            insertParameters.Add(fyear)
            Dim fequip_no As New SqlParameter("@equip_no", SqlDbType.VarChar, 30)
            fequip_no.Direction = ParameterDirection.Input
            fequip_no.Value = equip_no.Text
            insertParameters.Add(fyear)

            insertParameters.Add(fyear)
            insertParameters.Add(fsno)
            insertParameters.Add(fdescription)
            insertParameters.Add(fmake)
            insertParameters.Add(fequip_no)
            SqlDataSource1.Insert()

        End If
    End Sub
    Protected Sub Sqldatasource1_Inserting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs)
        e.Command.Parameters.Clear()
        For Each p As SqlParameter In insertParameters
            e.Command.Parameters.Add(p)
        Next
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
End Class

Hi there
just replace your gridview1 DataSourceID property

DataSourceID="SqlDataSource1"

Mark as solved if it helps you!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.