我是javascript的新手,我想用它来验证gridview(radgrid listview)中的用户控件。
这是我到目前为止所做的,但是javascript没有解雇。
我不想使用Range验证器,因为验证器错误消息即使在未显示时也会占用一些空间,并且在我的gridview中看起来不太好。
提前感谢您的帮助
安
HTML代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="sks_Creation.ascx.cs" Inherits="Sapphire.Control.Assessment.sks_Creation" %>
<asp:UpdatePanel ID="updPnl" runat="server">
<ContentTemplate>
<script type="text/javascript">
function validate() {
var grid = document.getElementById("<%= LV.ClientID%>");
for (var i = 0; i < grid.rows.length - 1; i++) {
var Mark = $("input[id*=txtMark]")
var ValMark = $("input[id*=lblValMark]")
if (Mark == 0) {
alert("Mark should be greater than 0");
ValMark = "Mark should be greater than 0";
return false;
}
}
}
</script>
<tlk:RadListView ID="LV" runat="server" Width="99%" OnNeedDataSource="LV_NeedDataSource" OnItemDataBound="LV_ItemDataBound" AllowPaging="true" ItemPlaceholderID="QuestionContainer">
<ItemTemplate>
<fieldset style="border: none;">
<table cellpadding="0" cellspacing="0" width="100%" class="SelectedCQLVRow" >
<tr>
<td>
<asp:Label ID="lblQuestion" CssClass="CQPanelQuestion" runat="server" Text='<%# Eval("Question") %>' visible="false"/>
<hrz:TextBox ID="txtMark" Text='<%# Eval("Mark") %>' runat="server" LabelText="Mark" />
<asp:Label ID="lblValMark" runat="server" ForeColor="Red" />
<div class="CQBottomRight" >
<tlk:RadButton ID="btnSave" runat="server" ToolTip="Save this question" Text="Save" Visible='<%# Boolean.Parse(Eval("IsEnabled").ToString()) %>'
CommandName="SaveGVQuestion" CommandArgument='<%# Eval("QID")%>' OnCommand="btn_ClickEvent" OnClientClick="validate()"
skin="Metro" Height="25px" Width="80px">
<Icon SecondaryIconCssClass="rbSave" SecondaryIconLeft="4" SecondaryIconTop="3"></Icon>
</tlk:RadButton>
</div>
</td>
</tr>
</table>
</fieldset>
</ItemTemplate>
</tlk:RadListView>
</ContentTemplate>
</asp:UpdatePanel>