DetailsView1.DataSource = "GetRegisteredUser";
DetailsView1.DataBind();
When I hit the button, I am getting the message below. Just to clarify, the EmpID is my first column of the query.
DataBinding: 'System.Char' does not contain a property with the name 'EmpID'.
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: DataBinding: 'System.Char' does not contain a property with the name 'EmpID'.
Source Error:
| Line 26: WebMsgBox.Show(TextBox1.Text); Line 27: DetailsView1.DataSource = "GetRegisteredUser"; Line 28: DetailsView1.DataBind(); Line 29: //} Line 30: } |
Source File: c:\Users\sgodin\Documents\Visual Studio 2010\WebSites\MaskFitAdmin\EHMaskSizeSet.aspx.cs Line: 28
Stack Trace:
| [HttpException (0x80004005): DataBinding: 'System.Char' does not contain a property with the name 'EmpID'.] System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +9805821 System.Web.UI.WebControls.DetailsView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +1444 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67 System.Web.UI.WebControls.DetailsView.PerformDataBinding(IEnumerable data) +12 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +123 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30 System.Web.UI.WebControls.DetailsView.DataBind() +4 EHMaskSizeSet.Button1_Click1(Object sender, EventArgs e) in c:\Users\sgodin\Documents\Visual Studio 2010\WebSites\MaskFitAdmin\EHMaskSizeSet.aspx.cs:28 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9752490 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +196 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724 |
I set up a profiler and when I run my app,. nothing gets executed. That means the DataBind() doesn't fire. The GridView expects the data where the first row is EmpID and it is not there.
What is wrong happening here? As I said, I used that method before and everything worked just fine.
Stanislav GodinPosted Feb 17, 2015, 9:26 AM
DetailsView1.DataSource = "GetRegisteredUser";
DetailsView1.DataBind();
GetRegisteredUser is a SqlDataSource defined on the web form.
In another project in a different web form I can't do the quotes. Look at the error above. I have to do this:
DetailsView1.DataSource = GetRegisteredUser;
DetailsView1.DataBind();
Why Microsoft allows passing the SqlDataSource using quotes in one form and doesn't allow it in another form? I have the same namespaces for both forms, and the web config files are the same except the server name.
Khargesh RajputPosted Feb 16, 2015, 10:27 PM
use any dataset or datatable as a valid datasource and bind with return data you want in gridview
Francis SusaimichaelPosted Feb 16, 2015, 7:51 PM
Stanislav GodinPosted Feb 16, 2015, 1:27 PM
DetailsView1.DataSource = GetRegisteredUser;
DetailsView1.DataBind();
Now, it worked! So, why in the worlds, it works with quotes in one web form and not in another web form? All the namespaces are identical, the dot net framework is the same and the web config files are the same.