Книга: C# 2008 Programmer

Displaying Publisher's Name

Displaying Publisher's Name

As Figure 17-15 shows, the publisher's ID appears in the GridView control under the pub_id field. It would be helpful to the user if the publisher's name displayed instead of its ID. To do that, switch to the source view of Default.aspx and within the <asp:GridView> element, replace the following element:

<asp:BoundField
 DataField="pub_id"
 HeaderText="pub_id"
 SortExpression="pub_id"/>

with this:

<asp:TemplateField
 HeaderText="Publisher">
 <ItemTemplate>
  <%#Eval("publisher.pub_name")%>
 </ItemTemplate>
</asp:TemplateField>

Essentially, this changes the header for the publisher column in the GridView to Publisher, and the values are now derived from the publisher.pub_name property of the DataClassesDataContext class.

 Press F5 to debug the application again to see the publishers' names instead of the publishers' IDs (see Figure 17-16).


Figure 17-16 

Оглавление книги


Генерация: 1.092. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз