Datagrid custom template help

K

Kasey Rybic

I am trying to put data from a field of a query in to the HeaderText arg and
I keep getting an error.
<asp:DataGrid id="dgMainCompany" runat="server" width="55%"
HorizontalAlign="Left"
AutoGenerateColumns="False"
BackColor="WhiteSmoke"
Font-Name="Verdana"
Font-Size="11pt">
<HeaderStyle BackColor="Thistle" ForeColor="Black" Font-Bold="True" />
<Columns>
<asp:TemplateColumn HeaderText=I_WANT_TO_PUT_COMPANY_NAME_HERE>
<ItemTemplate>
<table width="100%">
<tr>
<td><%# Container.DataItem("Address") %><br/>
<%# Container.DataItem("City") %>, <%# Container.DataItem("State")
%>&nbsp;<%# Container.DataItem("Zip") %></td>
</tr>
<tr>
<td><%# Container.DataItem("Phone1") %><br/>
<%# Container.DataItem("Fax") %></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

See section I_WANT_TO_PUT_COMPANY_NAME_HERE, I have tried several
permutations of <%# Container.DataItem("CompanyName") %> and can not get it
to work correctly. It works fine if I hard code in a string "COMPANY_NAME"
but I need to get the value here. Any feedback is always appreciated.
Thanks everybody. Happy Coding!

CK
 
S

Scott Allen

Hi Kasey:

Instead of using a data binding expression, set the HeaderText
property using a variable in your code behind class ( <%= CompanyName
%> ) where CompanyName is a protected or public property on the class.

Somehow I suspect the CompanyName field is not in the data source, if
the report was for only a single company the field would seem wasted
as it never changes for all the records.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top