GridView中任意一个checkbox选中,更改TextBox属性

 

<asp:GridView ID="FileList" runat="server"
AutoGenerateColumns="False" DataKeyNames="FullName">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chbNo" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
... Remaining BoundFields ...
</Columns>
</asp:GridView>

 Protected Sub gvSNList_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            For Each gvr As GridViewRow In Me.gvSNList.Rows
                Dim cb As CheckBox = CType(gvr.FindControl("chkNo"), CheckBox)

                If Not cb Is Nothing Then
                    'Add the CheckBox's ID to the client-side CheckBoxIDs array
                    ClientScript.RegisterArrayDeclaration("CheckBoxIDs", String.Concat("'", cb.ClientID, "'"))

                    'Run the ChangeStartNoAndEndNoStates client-side function whenever the
                    'checkbox is checked/unchecked
                    cb.Attributes("onclick") = "ChangeStartNoAndEndNoStates(this.checked);"
                End If
            Next
        Catch ex As Exception
            showAlert(ex.Message.ToString())
        End Try
    End Sub

 

//点击checkbox时,遍历CheckBoxIDs,看是否有checked,如果有,则将StartNo和EndNo设置为disabled
function ChangeStartNoAndEndNoStates()
{
    var isChecked = false;
   
    if (CheckBoxIDs != null)
    {
        for (var i = 0; i < CheckBoxIDs.length; i++)
        {
            var cb = document.getElementById(CheckBoxIDs[i]);
           
            if (cb.checked)
            {
                isChecked = true;
            }
        }
       
        if (isChecked)
        {
            document.getElementById("txtStartNo").disabled = true;
            document.getElementById("txtEndNo").disabled = true;           
        }
        else
        {
            document.getElementById("txtStartNo").disabled = false;
            document.getElementById("txtEndNo").disabled = false;   
        }
    }
}

 

 

posted @ 2008-11-19 16:08  南守拥  阅读(666)  评论(0编辑  收藏  举报