code blocks are not supported in this context in asp.net control

前端 未结 2 1760
广开言路
广开言路 2021-01-17 14:12

I\'m creating one html table. I want to hide the table row. I\'m putting the attributes runat=server and id for the particular row, but the row has

相关标签:
2条回答
  • 2021-01-17 14:16

    When you add a runat='server' to an HTML control you change the rendering and code blocks aren't supported inside. So if there are properties you need to change (style? class?) you probably have to instead of doing this:

    <tr id='myrow' runat='server'>
        <td> 
            your code here
        </td>
    </tr>
    

    Do something like this:

    <tr id='myrow' <%= GetRowProperties() %>>
        <td> 
            your code here
        </td>
    </tr>
    

    Note: runat='server' removed from tr. Then in your codebehind you can do something like this:

    protected string GetRowProperties()
    {
        return "class='myclass'"; // something like this
    }
    
    0 讨论(0)
  • 2021-01-17 14:23

    You can use data binding to control the visibility of a control. That should solve your problem.

    <tr runat="server">
    
        some content...
    
        <asp:PlaceHolder runat="server"
            visible='<%# (strFlag=="d") || (strApprvdFlag=="y") %>'>
    
            This content will only be rendered if strFlag is "d" or "y"
    
        </asp:PlaceHolder>
    
        more content...
    
    </tr>
    

    On your OnLoad method, you will need to call the DataBind() method to either the PlaceHolder, or any control that contains it, like the tr or even Page:

    protected override void OnLoad(EventArgs e) {
        base.OnLoad(e);
    
        Page.DataBind();
    }
    
    0 讨论(0)
提交回复
热议问题