sql - Hide Delete Button in Gridview if RowID links to Foreign Key -
vb.net - i've found other questions related this, none situation. i'm dealing 2 tables - "task" , "task_run."
i have gridview rows listing "tasks." come "task" table , each task has "tsk_id." want have delete button each task (row) , want delete button visible row if task not have run associated task "task_run" table. (i.e. not want user able delete task if has been run.)
table1 - "task" pky = "tsk_id"
table2 - "task_run" pky = "run_id" fky = "run_tsk_id"
i assume need have template field in gridview , have delete button conditionally show based on whether there rows in run table associated particular task id, stuck on how this. makes sense. appreciated. thanks!
you first task_id task_run table accordingly user if exist otherwise return 0 value , , placed task_id in gridview on label or textbox or hidden field visible=false property if not showing user, use command checking task have run or not user.
select ext.* , isnull((select top 1 run_tsk_id task_run run_tsk_id = ext.tsk_id),0) checkid task ext
then use gridview rowdatabound event hide or show delete button conditionally, code as.
protected sub grid_rowdatabound(sender object, e gridviewroweventargs) if e.row.rowtype = datacontrolrowtype.datarow dim lblcheckid label = directcast(e.row.findcontrol("lblcheckid"),label) dim deletebutton button = directcast(e.row.findcontrol("btndelete"), button) if cint(lblcheckid.text) > 0 deletebutton.visible = false else deletebutton.visible = true end if end if end sub
Comments
Post a Comment