hi,
I am trying to return some columns from my ms sql table and assigning url links to each row returned. i am trying to do so via a gridview.
this is the asp code i am using:
X marks the spot
Wheni run it i get the follow error:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Type 'System.Web.UI.WebControls.TemplateField' does not have a public property named 'DataField'.
Jayraj ChhayaPosted Apr 11, 2024, 2:19 PM
Check your code & compare this one.
Initialize GridView and Label Controls: Ensure that the GridView and label controls are properly initialized in the markup file (e.g., ASPX page) and linked to the corresponding controls in the code-behind.
Handle Data Binding Logic: Modify the
BindGridViewmethod to include proper initialization and error handling for the controls.One more thing, please ensure that the data is being retrieved successfully by running your query and debug the code. If the data is retrieved, then check if it is bound to the GridView
Jayraj ChhayaPosted Apr 12, 2024, 6:54 AM
Okay, fergus
If my answer is helpful to you, then please accept the answer.
fergusPosted Apr 11, 2024, 5:26 PM
yes i can retrieve the data in a table no problem but it wont come up for gridview so i know connecrtion and data retrieval is good.
fergusPosted Apr 11, 2024, 1:41 PM
yes still nothing showing up. perhaps i am not doing something correctly. i will share some of my CS code:
Jayraj ChhayaPosted Apr 11, 2024, 1:24 PM
Try this code
If you still face any error then share some more code or error details.
fergusPosted Apr 11, 2024, 1:15 PM
ok great i have taken your advice and cleaned it up and no more error messages - but i am not getting the rows to print on screen,
i toggled between AutoGenerateColumns="true" and false but i still cant get data to show up. i can see the grid ok in the design view but nothing shows up when i run it in the browser
Jayraj ChhayaPosted Apr 11, 2024, 12:29 PM
To resolve this issue, ensure that the
ItemTemplateis correctly defined within aTemplateFieldof theGridView. Here's an example of how to structure theTemplateFieldwith anItemTemplatecontaining anasp:HyperLinkcontrol:Make sure that the
ItemTemplateis enclosed within theTemplateFieldtags and that the control hierarchy is correct. Theasp:HyperLinkcontrol is valid for creating hyperlinks in ASP.NET.fergusPosted Apr 11, 2024, 12:16 PM
@Jayray thank you.....but its pulled up an error on the next time for itemTemplate:
Parser Error Message: System.Web.UI.WebControls.DataControlFieldCollection must have items of type 'System.Web.UI.WebControls.DataControlField'. 'ItemTemplate' is of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
Any idea what the caus eof this error is? is asp:hyperlink valid?
Jayraj ChhayaPosted Apr 11, 2024, 12:06 PM
The error message "Type 'System.Web.UI.WebControls.TemplateField' does not have a public property named 'DataField'" suggests that the TemplateField in the GridView is incorrectly configured. TemplateFields do not have a 'DataField' property; instead, you should use controls like Label or Literal within the ItemTemplate to display dynamic content.