TemplateColumn

  • Thread starter Thread starter Dave
  • Start date Start date
Basically you remove your <Asp:BoundColumn> columns and replace them with
<Asp:TemplateColumn> columns. A template column defines explicity what is
shown when in Item mode (not in edit mode) and when in Edit mode.

Normally every TemplateColumn has at the minimum an ItemTemplate and an
EditItemTemplate. If you ommit the EditItemTemplate you can make a column
read-only when in edit mode.

Here is a quick sample:

<ASP:DataGrid runat=server ... >
<COLUMNS>
<ASP:TEMPLATECOLUMN>
<ITEMTEMPLATE>
<asp:label id="lblItemCharge" Runat="server" CssClass="ChargeItem"><%#
Server.HtmlEncode(Container.DataItem("Charge")) %></asp:label>
</ITEMTEMPLATE>

<EDITITEMTEMPLATE>
<asp:TextBox id=txtEditCharge Runat="server" CssClass="ChargeInput"
Text='<%# Container.DataItem("charge") %>' MaxLength="10"></asp:TextBox>
</EDITITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
<ASP:TEMPLATECOLUMN>
repeat blah blah
</ASP:TEMPLATECOLUMN>
</COLUMNS>
</Asp:DataGrid>

HTH,
Greg
 

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

Back
Top