Protected Sub btnView_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnView.Click
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("WDDAssignment").ToString())
Dim Command As New SqlCommand("SpGetAllBySchool", connection)
Command.CommandType = CommandType.StoredProcedure
Command.Parameters.AddWithValue("Name", txtSchool.Text)
Dim daSchool As New SqlDataAdapter(Command)
Dim result As New DataSet
connection.Open()
daSchool.Fill(result, "Name")
connection.Close()
Session("MyDataSet") = result.Tables("Name")
grvView().DataSource = result.Tables("Name")
grvView.DataBind()
End Sub
Protected Sub grvView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grvView.PageIndexChanging
grvView.PageIndex = e.NewPageIndex
grvView.DataSource = Session("MyDataSet") grvView.DataBind()
End Sub
The DataSourceID of 'grvView' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found.
what should i do now? how to obtain data frm database? coz my gridview is not showing up during live.
Server Error in '/' Application.
The DataSourceID of 'grvView' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The DataSourceID of 'grvView' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): The DataSourceID of 'grvView' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found.]
System.Web.UI.WebControls.DataBoundControl.GetDataSource() +1801020
System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView() +159
System.Web.UI.WebControls.DataBoundControl.OnLoad(EventArgs e) +19
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Looking at your original posted code, this is wrong: grvView().DataSource. You need to remove the parenthesis. Maybe that's causing the problem, I don't know.
qhairy
Member
1 Points
13 Posts
Both DataSource and DataSourceID are defined on 'grvView'. Remove one definition.
Jan 26, 2013 08:05 AM|LINK
anyone knows this??
Protected Sub btnView_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnView.Click Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("WDDAssignment").ToString()) Dim Command As New SqlCommand("SpGetAllBySchool", connection) Command.CommandType = CommandType.StoredProcedure Command.Parameters.AddWithValue("Name", txtSchool.Text) Dim daSchool As New SqlDataAdapter(Command) Dim result As New DataSet connection.Open() daSchool.Fill(result, "Name") connection.Close() Session("MyDataSet") = result.Tables("Name") grvView().DataSource = result.Tables("Name") grvView.DataBind() End Sub Protected Sub grvView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grvView.PageIndexChanging grvView.PageIndex = e.NewPageIndex grvView.DataSource = Session("MyDataSet") grvView.DataBind() End SubMetalAsp.Net
All-Star
112051 Points
18235 Posts
Moderator
Re: Both DataSource and DataSourceID are defined on 'grvView'. Remove one definition.
Jan 26, 2013 08:12 AM|LINK
qhairy
Member
1 Points
13 Posts
Re: Both DataSource and DataSourceID are defined on 'grvView'. Remove one definition.
Jan 26, 2013 08:51 AM|LINK
this happen.
what should i do now? how to obtain data frm database? coz my gridview is not showing up during live.
Server Error in '/' Application.
The DataSourceID of 'grvView' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The DataSourceID of 'grvView' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found.
Source Error:
Stack Trace:
MetalAsp.Net
All-Star
112051 Points
18235 Posts
Moderator
Re: Both DataSource and DataSourceID are defined on 'grvView'. Remove one definition.
Jan 27, 2013 07:47 AM|LINK
oned_gk
All-Star
31143 Points
6365 Posts
Re: Both DataSource and DataSourceID are defined on 'grvView'. Remove one definition.
Jan 27, 2013 12:30 PM|LINK
If you have property value like datasourceid="sqldatasource1" dont use gv.datasource=dt
If you have gv.datasource=dt, remove datasourceid property value like datasourceid="sqldatasource1".