我向我的InsertItemTemplate添加了一个RequiredFieldValidator,它似乎工作正常。但是,我遇到的问题是,现在我无法在ListView中执行其他任何操作(如编辑或删除项目),除非必需的字段有值。有什么办法可以在用户单击InsertItemTemplate上的'插入'按钮或我可以执行的一些其他小技巧时手动进行验证,以便用户不必首先输入值即可删除其他内容列表?在ListView插入/编辑模板中验证控件
感谢
我向我的InsertItemTemplate添加了一个RequiredFieldValidator,它似乎工作正常。但是,我遇到的问题是,现在我无法在ListView中执行其他任何操作(如编辑或删除项目),除非必需的字段有值。有什么办法可以在用户单击InsertItemTemplate上的'插入'按钮或我可以执行的一些其他小技巧时手动进行验证,以便用户不必首先输入值即可删除其他内容列表?在ListView插入/编辑模板中验证控件
感谢
是, 设置CausesValidation属性为false,你不希望他们触发验证控件。
A_Nablsi,
请提供代码,您的解决方案打开插入新的验证控件在断电时编辑/更新模式或将编辑/更新验证控件关闭时,无论是编辑和插入行处于活动状态,同时。这个使用你的理论解决方案的代码失败了,并且对updateButton有一个空引用。
LinkButton updateButton = LVTasks.EditItem.FindControl("UpdateButtonTask") as LinkButton;
updateButton.CausesValidation = false;
的作品是增加确认团组的解决方案。
在EditItemTemplate和Update按钮中包含ValidatorGroup =“myVGEdit”和您的Validator控件。
将ValidationGroup =“myVGInsert”与Validator控件包含在InsertItemTemplate和Insert按钮中。
<asp:ListView ID="LVTasks" runat="server"
DataKeyNames="IDTask"
DataSourceID="LDS_LVTasks"
InsertItemPosition="FirstItem"
oniteminserting="LVTasks_ItemInserting"
onitemupdating="LVTasks_ItemUpdating"
onitemcommand="LVTasks_ItemCommand"
>
<EditItemTemplate>
<asp:TextBox ID="TaskUpdateTextBox" runat="server"
Text='<%# Bind("Task") %>'
TextMode="MultiLine" Rows="1" Font-Bold="true" Width="300px"
/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please Set Task title"
ControlToValidate="TaskUpdateTextBox"
ValidationGroup="myVGUpdate"
/>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Cancel"
CausesValidation="False"
ToolTip="Cancel - Abort - No Changes"><div class="Cancel"></div></asp:LinkButton>
<asp:LinkButton ID="UpdateButtonTask" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Update"
CausesValidation="True"
ValidationGroup="myVGEdit"
ToolTip="Save Changes - Update"><div class="Update" ></div></asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TaskInsertTextBox" runat="server" Text='<%# Bind("Task") %>'
TextMode="MultiLine" Rows="1" Font-Bold="true" Width="300px"
/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please Set Task title"
ControlToValidate="TaskInsertTextBox"
ValidationGroup="myVGInsert"
/>
<asp:LinkButton ID="CancelButton" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Cancel"
CausesValidation="False"><div class="Clear" ></div></asp:LinkButton>
<asp:LinkButton ID="InsertButtonTask" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Insert"
CausesValidation="true"
ValidationGroup="myVGInsert"
><div class="Insert" ></div></asp:LinkButton>
</InsertItemTemplate>
太棒了!谢谢。 – Curtis 2010-10-29 16:24:19
:)不客气,祝你好运。 – 2010-10-29 16:34:41