检查使用javascript在页面列表视图中呈现多少个复选框..... [英] Check How many checkboxes are rendered in listview on page using javascript.....

查看:72
本文介绍了检查使用javascript在页面列表视图中呈现多少个复选框.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个listview,其中包含

I have a listview which contains

<asp:Listview>
<LayoutTemplate>
    <ChechBox>
</LayoutTemplate>
<ItemTemplate>
    <txtbx1>
</ItemTemplate>
</asp:Listview>





当用户选择特定行时,我想使用javascript来验证所选行的文本框。



用户可以选择任意行数....



需要帮助...



Thnx提前..:)



When user selects specific row I want to validate textbox of that selected row using javascript....

user can select any number of rows....

Need Help...

Thnx in advance.. :)

推荐答案

根据您的评论,您似乎想要添加必填字段验证列表框中的文本框



在这种情况下,您可以在listview控件的itemcommand事件中尝试下面的内容



As per your comment it seems that you want to add required field validation for your textbox inside the listbox

In that case you can try some thing like below in the itemcommand event of the listview control

ListViewDataItem item = (ListViewDataItem)e.Item;
            TextBox tbTest = (TextBox)currentItem.FindControl("tbTest ");            	

RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator();
            requiredFieldValidator.ID = "rfvID" + id.ToString();// some autogenerated id
            requiredFieldValidator.ErrorMessage = "Required";
            requiredFieldValidator.Text = "Cannot be blank";
            requiredFieldValidator.ValidationGroup = "validationGroupId";            
            requiredFieldValidator.ControlToValidate = tbTest.ID;
            item.Controls.Add(requiredFieldValidator);
            requiredFieldValidator.Validate();

            if (requiredFieldValidator.IsValid)
            {

            //do something 

            }

           else { 
		// Show error 
		}





希望这有帮助



Hope this helps


<script type="text/javascript">
        function Validate() {
            var tr =


#tblListView tr);

var count = tr.length;
for (i = 0 ; i < ; count; i ++){

var str = ' ListView1_chkbx1_0';

if (document.getElementById(' ListView1_chkbx1 _' + i)。已检查){

var a = ' ';
var str1 = str.substr( 0 10 );
var str2 = str.substr( 17 2 );
var txtID = document.getElementById(str1 + ' txtID _' + i)。 value ;
if (txtID == ){
a = ' false';

}
var txtCity = document.getElementById(str1 + ' txtCity _' + i)。 value ;
if (txtCity == ){
a + = ' false';
}
var txtCountry = document.getElementById(str1 + ' txtCountry _' + i)。 value ;
if (txtCountry == ){
a + = ' false';
}
var txtPostalCode = document.getElementById(str1 + ' txtPostalCode _' + i)。 value ;
if (txtPostalCode == ){
a + = ' false';
}
如果(a!= ' '){
alert(' 请检查行' +第(i + 1));
}
}
}
}
< / 脚本 >
("#tblListView tr"); var count = tr.length; for (i = 0; i < count; i++) { var str = 'ListView1_chkbx1_0'; if (document.getElementById('ListView1_chkbx1_' + i).checked) { var a = ''; var str1 = str.substr(0, 10); var str2 = str.substr(17, 2); var txtID = document.getElementById(str1 + 'txtID_' + i).value; if (txtID == "") { a = 'false'; } var txtCity = document.getElementById(str1 + 'txtCity_' + i).value; if (txtCity == "") { a += 'false'; } var txtCountry = document.getElementById(str1 + 'txtCountry_' + i).value; if (txtCountry == "") { a += 'false'; } var txtPostalCode = document.getElementById(str1 + 'txtPostalCode_' + i).value; if (txtPostalCode == "") { a += 'false'; } if (a != '') { alert('Please Check Line ' + (i+1)); } } } } </script>


这篇关于检查使用javascript在页面列表视图中呈现多少个复选框.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆