ListView控件中的验证 [英] Validation in ListView Control

查看:47
本文介绍了ListView控件中的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图控件

< LayoutTemplate>和< ItemTemplate>



项目模板中有各种文本框



来自这个ListView用户会选择一些行并点击按钮Go ....



btn点击我想用必填字段验证器验证只出现在这些选定行中的文本框( s)...



请提供你有的任何技巧或逻辑...........!

I've one list view control with
<LayoutTemplate> and <ItemTemplate>

in Item Template there are various textboxes

from this ListView user will select some rows and click on the button Go....

on this btn Click I want to validate with Required Field Validator to text boxes present only in these Selected row(s)...

Please provide any tricks or logic u have...........!

推荐答案

嘿那里,



我从你的描述中理解,你只想验证那些选择了行的文本框。以下是您需要遵循的几个步骤。



1.为行的各个TextBox添加RequiredFieldValidator(我认为您已经这样做了),并设置其已启用=false ValidationGroup =



2.其次,为您的按钮添加 ValidationGroup =YourValidationGroupName



3.添加 OnCheckedChanged CheckBoxes事件和Set AutoPostBack =true



4.以下是您在 OnCheckedChanged 事件中需要做的事情:

- 查找所有 RequiredFieldValidator 控制所选行的每个TextBox并设置 Enabled =true ValidationGroup =YourValidationGroupName

以下是示例代码:
Hey there,

What I understand from your description, you want to validate only those textboxes where row is selected. Here are a few steps you need to follow.

1. Add RequiredFieldValidator for individual TextBoxes of the row (I think you have already done that), and set its Enabled = "false" and ValidationGroup=""

2. Second, Add a ValidationGroup = "YourValidationGroupName" for your Button.

3. Add OnCheckedChanged event for the CheckBoxes and Set AutoPostBack="true"

4. Here is what you need to do inside the OnCheckedChanged event:
- Find all the RequiredFieldValidator controls for each TextBox of the selected row and set Enabled="true" and ValidationGroup="YourValidationGroupName"
Here is the sample code:
protected void checkbox1_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk = sender as CheckBox;
            if (chk != null)
            {
                ListViewDataItem item = chk.NamingContainer as ListViewDataItem;
                if (item != null)
                {
                    RequiredFieldValidator RFV1 = item.FindControl("RequiredFieldValidator1") as RequiredFieldValidator;
                    if (RFV1 != null)
                    {
                        RFV1.Enabled = chk.Checked;
                        if (chk.Checked)
                            RFV1.ValidationGroup = "YourValidationGroupName";
                        else
                            RFV1.ValidationGroup = "";
                    }

                    RequiredFieldValidator RFV2 = item.FindControl("RequiredFieldValidator2") as RequiredFieldValidator;
                    if (RFV2 != null)
                    {
                        RFV2.Enabled = chk.Checked;
                        if (chk.Checked)
                            RFV2.ValidationGroup = "YourValidationGroupName";
                        else
                            RFV2.ValidationGroup = "";
                    }
                    //Do the same for remaining RequiredFieldValidators
                }
            }
        }





如果有帮助请告诉我。



Azee ......



Let me know if it helps.

Azee...


这篇关于ListView控件中的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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