Книга: C# 2008 Programmer

Making the Publisher Field Editable

Making the Publisher Field Editable

Now select a record, and click the Edit link. Notice that the publisher is not editable (see Figure 17-21).


Figure 17-21

Here's how to make the publisher field editable. In the source view of Default.aspx, insert the following highlighted code:

<asp:TemplateField HeaderText="Publisher">
 <ItemTemplate>
  <%#Eval("publisher.pub_name")%>
 </ItemTemplate>
 <EditItemTemplate>
  <asp:DropDownList
  
   DataSourceID="LinqDataSource2"
   DataTextField="pub_name"
   DataValueField="pub_id"
   SelectedValue='<%#Bind("pub_id")%>'
   runat="server">
  </asp:DropDownList>
 </EditItemTemplate>
</asp:TemplateField>

This creates a dropdown list within the GridView control (under the Publisher column) and displays a list of publishers available.

Press F5 to debug the application again. A title's publisher can now be changed (see Figure 17-22).


Figure 17-22

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


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