Developing Matt

My Technical Journal

Gridview lessons I learnt 1: dynamically set enabled property

leave a comment »

I want the enabled property of a button(or textbox) in my gridview to be based on MY logic. How do you do THAT?

~Change the field to a template field.
~Write a function with your funky logic in your code behind and call it

Function ScrewBallLogic(dataitem as object) as boolean
return true
end function

    ~In the html source (or you can edit the template) set the property of Enabled to call this function:

    ~example that won’t work: Enabled = ‘<%#ScrewBallLogic(bind(“yourdataboundfield”))%>’
    ~Instead of the default bind, change it to Eval to incorporate two way binding
    ~This will work until you hit a dbnull at which it will crash. The reason is that your function needs to be an object. So make sure your parameter for your function is an object, not anything else. Objects can handle nulls. Function ScrewBallLogic(dataitem as object).
    ~I haven’t figured out why, but the way you are supposed to do this is like the following (including container and databinder calls. Can you tell me why? Enabled = ‘<%#ScrewBallLogic(databinder.eval(container.dataitem,”yourdataboundfield”))%>’

    The nice thing is that this same logic will work with the text property, visible property as well as several others.


    Written by matt

    September 6, 2007 at 5:55 am

    Posted in

    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )


    Connecting to %s

    %d bloggers like this: