我正在使用自定义验证器来调用javascript函数进行验证.我的问题是我需要能够动态更改错误消息.这是代码:
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="fcnValid1"
ErrorMessage="" Display="None" ValidateEmptyText="True">
</asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" ShowMessageBox="True" ShowSummary="False" />
function fcnValid(source, args) {
var Status = document.getElementById("<%=ddlStatus.ClientID%>").value
if (Status == "In Underwriting") {
if (document.getElementById("<%=txtRequestor.ClientID%>").value == "") {
//sender.errormessage = "Test1"
//sender.innerHTML = "Test2";
document.getElementById("<%=txtRequestor.ClientID%>").focus();
args.IsValid = false;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我遇到了除零的问题.如果分母为零,我希望该值为零.当我尝试使用时nullif
,我最终得到零或一个计算值.
这是SQL:
Select
StateCode, Month1Date,(Sum(Order)/Sum(Value)) as myValue
from tblOrders
inner join tblStates on OrderStateCode = StateCode
group by StateCode, Month1Date
Run Code Online (Sandbox Code Playgroud) 我正在使用参数化查询将我的经典asp转换为.Net.我的问题是,在我的经典应用中,我会用ascii equivelent替换撇号'
现在我想用真正的撇号替换数据库中的那个值.我不确定语法应如何做到这一点.我可以找到,'
但我不知道如何更换.以下是我试图运行该错误的简单更新.
update tblCustomer set Name = replace(Name '''
,,'''')
我想基于比较当前行值(第2列)和前一行值来格式化gridview.因此,如果它们是相同的,背景颜色将是相同的,例如绿色.如果它们不相同,则背景颜色为红色.例如:
Gridview values
Car 1 (bg color green)
Car 1 (bg color green)
Car 2 (bg color red)
Car 3 (bg color green)
Car 3 (bg color green)
Car 3 (bg color green)
Run Code Online (Sandbox Code Playgroud)
我无法让这个工作.这是我想出的代码.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
If Not e.Row.DataItem Is Nothing Then
'switch for first row
If e.Row.RowIndex = 1 Then
Dim Gprev As GridViewRow = GridView1.Rows(e.Row.RowIndex - 1)
If Gprev.Cells(1).Text = e.Row.Cells(1).Text Then
'e.Row.Cells(1).Text …
Run Code Online (Sandbox Code Playgroud) 我在尝试在gridview中触发rowcommand事件时遇到问题.我按照MSDNet的代码示例,但我无法弄清楚它为什么不起作用.代码如下.谢谢.
<asp:GridView ID="GridViewProducts" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
CellPadding="5" CellSpacing="1" DataKeyNames="Pkey"
DataSourceID="SqlDataSourceProducts" ForeColor="Black" GridLines="Vertical">
<FooterStyle BackColor="#CCCCCC" />
<PagerSettings PageButtonCount="20" />
<Columns>
<asp:BoundField DataField="Product" HeaderText="Product" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Interest">
<ItemTemplate>
<asp:DropDownList ID="ddlProductInterest" runat="server" SelectedValue='<%# Bind("ProductInterest") %>'>
<asp:ListItem></asp:ListItem>
<asp:ListItem>Low</asp:ListItem>
<asp:ListItem>Medium</asp:ListItem>
<asp:ListItem>High</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button runat="server" ID="TestButton" Text="Button" CommandName="Test"
CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="center" />
<ItemStyle HorizontalAlign="center" />
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" …
Run Code Online (Sandbox Code Playgroud) 我不知道为什么这不起作用.
我正在验证登录的人是否具有正确的安全性,如果他们不这样做我想将他们重定向到另一个页面.
如果它们具有正确的安全性,则页面上的其余代码将继续执行.
当我单步执行代码时,它会执行response.redirect,但页面会继续加载.
strSQL = "Select * from tblSecurity Where SFID = '" & Right(My.User.Name, 4) & "' and (SecurityLevel = '900' or SecurityLevel = '850')"
ds = objData.SQLExecuteDataset(strSQL, CommandType.Text)
If ds.Tables(0).Rows.Count = 0 Then
Response.Redirect("~/NotAuthorized.aspx", False)
End If
Run Code Online (Sandbox Code Playgroud) asp.net ×4
gridview ×2
sql ×2
vb.net ×2
.net ×1
ajax ×1
javascript ×1
rowcommand ×1
sql-server ×1