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

it2022-05-09  21

 

<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;            }     } }

 

 

转载于:https://www.cnblogs.com/nanshouyong326/archive/2008/11/19/1336762.html

相关资源:数据结构—成绩单生成器

最新回复(0)