Last post Aug 05, 2010 03:22 AM by Qin Dian Tang - MSFT
Aug 02, 2010 02:16 PM|braddwalker|LINK
I'm facing a problem with using a custom built server control in a databound context, and I'm not sure if what I'm trying to do is even possible. Here's the run-down.
I have a server control which performs some logic, and based on the outcome, will display the contents of one of two templates defined in that control. Here's an example:
<asp:Label runat="server" Text="The condition passed!" />
<asp:Label runat="server" Text="The condition failed!" />
So far, so good. The control works as expected, and depending on the conditions, I'll see one of the two outputs. What I'd like to be able to do is place this control inside of another template, say a GridView TemplateField ItemTemplate, and then be able
to use bound elements that originate from the gridview. For example:
<asp:GridView runat="server" DataSourceID="MyDataSource">
<asp:Label runat="server" Text='<%#Eval("message") %>' />
Where "message" is a bound data item that comes from the GridView's datasource. As best I can tell this all boils down to setting up the databinding in my TemplateContainers correctly, but I'm not sure how to proceed. Any guidance would be greatly appreciated.
Aug 05, 2010 03:22 AM|Qin Dian Tang - MSFT|LINK
You can add two properties into custom control. One for deciding which condition should be displayed. One for the text will be displayed. Then you can just bind TestControl like this:
<bw:TestControl runat="server" PositiveOrNegative="Positive" Text='<%# Eval("message") %>' >
You don't need to set two Condition any more.