简体   繁体   中英

Call a function in code behind in aspx?

I have this:

<ItemTemplate>
    <asp:CheckBox ID="cbRemove" runat="server" 
        Visible='<%# (string)Eval("GroupDescription") != "Default" %>' />
</ItemTemplate>

Only problem is, it might not be 'Default'. Is there a way I could call a function like GetDefaultName in my code behind that would get it from the database?

it will help you...

(string)Eval("GroupDescription") != "Default" ? GetDefaultName() : "Default"

in your class file write function like below..

protected string GetDefaultName()
{
    return "Your Default Name";
}

But i am not able to get why you pass this to Visible Property....?

in your markup, call a server side function like this:

Visible = '<%# GenerateVisibility()  %>'

in your code behind, create a function like this:

protected bool GenerateVisilbity()
{
//other code here if needed... such as your GetDefaultName()
//do your logic and decide whether or not to return a "true" or "false" boolean

//sample return value below
return Eval("GetDefaultName");//must return boolean value

}

*edit to return boolean value, earlier i snagged it from my open project, was using it to return a custom javascript function as a string to bind to clientside event...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM