您好我有一个javascript,我需要在datagrid itemdabound期间每行运行它。但是我使用下面的代码,它只显示一次。有人会告诉我如何解决问题。提前谢谢。
代码:
Private Sub dgrdConfirmed_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles dgrdConfirmed.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim dr As DataRow = CType(e.Item.DataItem, DataRowView).Row
If (Not Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), "addWarning")) Then
Dim cs As ClientScriptManager = Page.ClientScript
cs.RegisterStartupScript(Page.GetType(), "addWarning",
"<script language='javascript' type='text/javascript'>addWarning
();</script>")
Else
Dim lt As New Literal
lt.Text = "<script type='text/javascript'>addWarning()</script>"
lt.Mode = LiteralMode.Transform
End If
End Select
End Sub
有我的javascript:
<script type="text/javascript" >
function addWarning(e) {
alert('addWarning');
}
</script>
答案 0 :(得分:0)
我认为最好循环jquery中的gridview行而不是在数据绑定上调用javascript,你可以使用这段代码,并且不要忘记使用gridview的ClientIDMode静态:
$("#GridViewID tr").each(function () {
var checkBox = $(this).find("input[type='checkbox']");
var textBox = $(this).find("input[type='text']");
if ($(checkBox).is(':checked')) {
if (textBox.val().length === 0) {
alert("Warning Length 0 !!");
}
else {
alert("Warning Length diffrent of 0 !!");
}
}
});