Click here to Skip to main content
15,909,827 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I've been searching Google for 2 days.

I'm trying to get a gridview on a page and it's just not working. I've done this hundreds of times on this site, never a problem. This is not a matter of a missing field in the SQLDataSource. The query runs fine in the "configure datasource" wizard.

Here is the gridview. I took out the rest of the fields.
ASP.NET
<asp:GridView ID="GridView1" 
	runat="server" 
	AllowPaging="True" 
	AllowSorting="True" 
	AutoGenerateColumns="False" 
	PageSize="200"
        GridLines="Vertical"
	CellPadding="4"
	Font-Size="Medium"
	CssClass="gridviewPageGRID" 
	DataSourceID="SqlDataSource1" 
	DataKeyNames="Address_Hash">
	<Columns>
	<asp:TemplateField HeaderText="Address" SortExpression="Address">
		<ItemTemplate>
			<asp:Label ID="l3" runat="server" Text='<%# Eval("Address")%>'/>
		</ItemTemplate>
	</asp:TemplateField>

	</Columns>
</asp:GridView>


Here is the SQLDataSource:
SQL
SELECT CASE COALESCE(POBox,'') 
         WHEN '' THEN 
                      Street_Number 
         + ' '      + Street_PreDir 
         + ' '      + Street_Name 
         + ' '      + Street_Suffix 
         + ' '      + Street_PostDir 
         + '<br />' + City 
         + ', '     + State 
         + ' '      + ZIP 
         ELSE 
              'PO Box ' + POBox 
         + '<br />'     + City 
         + ', '         + State 
         + ' '          + ZIP 
       END                               AS Address
  FROM ERP.dbo.A_Address_Master


This SQL has worked fine on other pages in the site. The *only* field returned is Address, so why is this bombing? The SQL works in Toad, it works in setting up the data source in VS, so what's wrong with the gridview?
Posted

C#
<asp:label runat="server" id="lblGvPengumuman" text="<%# Bind("Address") %>" ></asp:label>

Try this.
 
Share this answer
 
v2
Comments
pixelmeow 9-Jan-14 11:18am    
Thank you for your suggestions. I got this error:

Parser Error Message: The server tag is not well formed.

What do you suggest?
Gitanjali Singh 9-Jan-14 12:20pm    
Updated the solution .please try this.
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Address") %>' CssClass="grid"></asp:Label>
 
Share this answer
 
Comments
pixelmeow 9-Jan-14 11:18am    
Thank you for your suggestions. I got this error:

Parser Error Message: The server tag is not well formed.

What do you suggest?
CHill60 9-Jan-14 13:00pm    
Which of these did you actually try? Solution 1 gives me an error but Solution 2 didn't
pixelmeow 9-Jan-14 13:14pm    
I tried both. It seems the "bind" command was the problem in the second, but the first gave "The server tag is not well formed." regardless of whether I used bind or eval. I changed bind back to Eval in the second one and it went back to the original error.

I've been comparing the first solution with what I used, and the first solution has been changed. It was: <asp:label runat="server" id="lblGvPengumuman" text="<%# Eval("Address") %>" xmlns:asp="#unknown">. I changed mine to match it and got the same error, "The server tag is not well formed.".
Praveen_P 10-Jan-14 0:48am    
hi pixelmeow
in your tag you used double quotes in eval scriptlet like text="<%# Eval("Address") %>" instead of use single quotes like text='<%# Eval("Address") %>'
pixelmeow 10-Jan-14 11:25am    
Thanks. I've always used text='<%# Eval("Address") %>' and never had a problem. Using the quotes differently gives "BC30201: Expression expected."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900