views:

25

answers:

1

Hi. I was having problems inserting a string into the following tag :

<tr id="rowBulkOptions" style='<%# sBulkOptionsRowStyle %>'>

Don't ask why I'm using tables :)

sBulkOptionsRowStyle is a Public string in the aspx.vb file.

Seemingly the only way I can get this to render is to put

Page.DataBind()

in the Page_Load, Page_PreRender etc.. However this causes me problems because Page.DataBind() binds all controls on the page.

I could use <%= BUT another part of the code inserts controls into the page and apparently you can't use <%= and insert controls.

Is there a way I can just say 'look, put sBulkOptionsRowStyle into the page please!' ?

Thanks.

+1  A: 

The <%# tag is used when binding to a repeating control, I take it this is not what you are doing?

As you are dynamically modifying the controls then as you stated you can also not use <%=.

My suggestion would be that you add the tag runat="server" to your tr and then assign the variable to the Style attribute of the control within the page load/init of your code behind.

e.g.

<tr id="rowBulkOptions" runat="server">

And in code behind

rowBulkOptions.Attributes["Style"] = sBulkOptionsRowStyle;
Robin Day
Ok now I feel super-stupid! I was sure that I couldn't give a <tr> tag the runat="server" attribute. As a consequence of this erroneous belief I've spent the last 3 days trying to do all kinds of crazy workarounds! Thanks :)
El Ronnoco
If you make it `runat="server"` it will become an `System.Web.UI.HtmlControls.HtmlTableRow`. One thing to also note though is even if it isn't in HtmlControls you can also declare ANY html control as an` HtmlGenericControl`.
Robin Day