asp.net - IIF statement to determine visibility of ImageButton in GridView not evaluating properly -
i have gridview displays user info along 2 template fields imagebuttons. 1 open detailsview edit user information. other edit user's password.
in code behind, have 3 iif statements check criteria. based on combinations of criteria, want imagebuttons either show/not show appropriately.
here code behind:
protected sub gvusers_rowdatabound(byval sender object, byval e system.web.ui.webcontrols.gridviewroweventargs) handles gvusers.rowdatabound dim isprovisioned boolean dim acceptedtos boolean dim issuspended boolean 'hide password change option users have not yet been provisioned or have not accepted tos agreement or have been suspended' if e.row.rowtype = datacontrolrowtype.datarow , _ directcast(sender, gridview).editindex <> e.row.dataitemindex isprovisioned = iif(string.isnullorempty(e.row.dataitem(guser.columns.dateadded).tostring), false, true) acceptedtos = iif(string.isnullorempty(e.row.dataitem(guser.columns.tostimestamp).tostring), false, true) issuspended = iif(string.isnullorempty(e.row.dataitem(guser.columns.suspenddate).tostring), false, true) dim btnadminedit imagebutton = directcast(e.row.findcontrol("btnadminedit"), imagebutton) dim btnadminselect imagebutton = directcast(e.row.findcontrol("btnadminselect"), imagebutton) btnadminedit.visible = not (issuspended) andalso isprovisioned andalso acceptedtos btnadminselect.visible = isprovisioned else gvusers.emptydatatext = "no records found matching specified criteria." end if end sub
don't know changed because code did work @ 1 point. however, when test page, both imagebuttons seem show no matter what. while debugging, saw seemed "evaluate" each row same way. in, each row went through iif statements, returned same values, if not true.
i have hunch it's taking first row's values , reusing how, or evaluating same row; that's why returns same values , shows imagebuttons, though not supposed visible according iif statements.
any appreciated i'm not sure how resolve here.
well, after delving little deeper, found causing problem.
the last change made before seeing problem addition of column displayed in gridview. distorted index of columns iif statements not checking correct datafields , thus, evaluating incorrectly.
so, code behind posted work , luckily proved wasn't going crazy. logic correct!
thanks took time glance @ question!
Comments
Post a Comment