template column generation problem

  • Thread starter Thread starter KK
  • Start date Start date
K

KK

Hi

I am showing some data in the datagrid.
I also have a template column.
Inside that template column I am going
to show 1 to 5 link buttons.

The problem i am having is, like in the
traditional ASP, can I use <%%> script blocks
as below ?

<datagrid>
<....>
<asp:TemplateColumn>.....
<ItemTemplate>
<table>
<tr>
<% if (DataBinder.Eval(Container.DataItem, "X") != NULL)%>
<td>draw the linkbutton for X</td>

<% if (DataBinder.Eval(Container.DataItem, "Y") != NULL)%>
<td>draw the linkbutton for Y</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</datagrid>

I am not sure how can i dynamicaly create the link button as shown above
If its value is not null in the dataset.

regards
KK
 
The <% ... %> expressions will be evaluated only once (not as part of the
databinding) and you dont want that.

You should rather do the following
- place each linkbutton in the template (no <%IFs )
- databind the desired properties of the linkbuttons in the usual
fashion (assuming value is not null)
- additionally, databind its "Visible" property to an expression which
turns false when value is null

That should do the trick: controls with Visible=false will not be rendered.
Regards
Jose.
 
Back
Top