Stanislav Godin

Stanislav Godin

  • NA
  • 8
  • 2.6k

DataBind doesn't fire on GridView

Feb 16 2015 9:58 AM
I have a very strange problem. I am developing the ASP.Net C# WebForm. I have a GridView with a sqldatasource and a textbox where I set a parameter from to the datasource. If I set the datasource on the GridVeiw itself, it works fine. I send a parameter and bind the GridView. I need to have a button and fire the DataBind() event from there. I had this scenario before and everything worked OK on other GridView's. So, I remove the datasource from the GridView and leave it with None, I put a button and placed my code there:


       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.



Answers (4)