摘要:[ASP.NET] 在GridView中添加CheckBox後,判斷CheckBox是否有點選來決定GridView中的控制項啟用與否
問題 : 想要在GridView中加入CheckBox,當使用者點選CheckBox後,讓GridView裡面的其他控制項能夠使用
原本想要在GridView外做個Button來判斷
但是這樣實在不符合需求...Orz|||
在參考 http://social.msdn.microsoft.com/Forums/zh-TW/236/thread/58481727-bba7-485b-b111-8257a711e7f3
稍做修改得到自己需要的效果
.vb
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim rChkBox As CheckBox = e.Row.Cells(0).FindControl("CheckBox1")
Dim rFileUpload As FileUpload = e.Row.Cells(2).FindControl("FileUpload1")
Dim rBtn As Button = e.Row.Cells(2).FindControl("BtnUpload")
rChkBox.Attributes("onclick") = String.Format("ChangeTextBoxEnable('{0}','{1}',this.checked);", rFileUpload.ClientID, rBtn.ClientID)
End If
End Sub
.aspx
<script type="text/javascript">
function ChangeTextBoxEnable(id1,id2, enable) {
document.getElementById(id1).disabled = !enable;
document.getElementById(id2).disabled = !enable;;
}
</script>

在此記錄