Asp.net 代码隐藏正在向应用程序传递错误的值
我试图根据列的值在gridview中显示特定的超链接Asp.net 代码隐藏正在向应用程序传递错误的值,asp.net,gridview,Asp.net,Gridview,我试图根据列的值在gridview中显示特定的超链接 <%If existsOtherParcel = "Y" Then%> Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br /> <asp:HyperLink ID="OtherParcelHyperLink" run
<%If existsOtherParcel = "Y" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="OtherParcelHyperLink" runat="server"
NavigateUrl='<%# Eval("OtherParcel", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br />
<asp:Label ID="notOnSale" runat="server" Text="Land is not on sale." Font-Bold="True"></asp:Label><br /><br />
<%ElseIf existsOtherParcel = "N" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="LocationMapHyperLink" runat="server"
NavigateUrl='<%# Eval("Property_ID", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br /><br />
<%End If%>
<asp:HyperLink ID="PRCHyperLink" runat="server"
NavigateUrl='<%# Eval("UnformattedParcelNumber", "http://URL/default.asp?sparcelno={0}&stemp=&dSearch=houseno&dreport=propcard&report=&dReportName=Property Card") %>'
Text="Property Record Card" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
这是我的GridView: <%If existsOtherParcel = "Y" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="OtherParcelHyperLink" runat="server"
NavigateUrl='<%# Eval("OtherParcel", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br />
<asp:Label ID="notOnSale" runat="server" Text="Land is not on sale." Font-Bold="True"></asp:Label><br /><br />
<%ElseIf existsOtherParcel = "N" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="LocationMapHyperLink" runat="server"
NavigateUrl='<%# Eval("Property_ID", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br /><br />
<%End If%>
<asp:HyperLink ID="PRCHyperLink" runat="server"
NavigateUrl='<%# Eval("UnformattedParcelNumber", "http://URL/default.asp?sparcelno={0}&stemp=&dSearch=houseno&dreport=propcard&report=&dReportName=Property Card") %>'
Text="Property Record Card" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
代码隐藏:
Protected Sub TaxSaleGridView_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles TaxSaleGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
OPval = DirectCast(e.Row.DataItem, Data.DataRowView)("OtherParcel").ToString()
Select Case OPval
Case Is <> Nothing
existsOtherParcel = "Y"
e.Row.Cells(3).BackColor = System.Drawing.Color.Yellow
Case Is = Nothing
existsOtherParcel = "N"
e.Row.Cells(3).BackColor = System.Drawing.Color.YellowGreen
e.Row.Cells(3).Text = TaxSaleGridView.Rows.Count
End Select
End If
<%If existsOtherParcel = "Y" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="OtherParcelHyperLink" runat="server"
NavigateUrl='<%# Eval("OtherParcel", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br />
<asp:Label ID="notOnSale" runat="server" Text="Land is not on sale." Font-Bold="True"></asp:Label><br /><br />
<%ElseIf existsOtherParcel = "N" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="LocationMapHyperLink" runat="server"
NavigateUrl='<%# Eval("Property_ID", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br /><br />
<%End If%>
<asp:HyperLink ID="PRCHyperLink" runat="server"
NavigateUrl='<%# Eval("UnformattedParcelNumber", "http://URL/default.asp?sparcelno={0}&stemp=&dSearch=houseno&dreport=propcard&report=&dReportName=Property Card") %>'
Text="Property Record Card" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Protected Sub-TaxSaleGridView_RowDataBound(发送方作为对象,e作为System.Web.UI.WebControls.GridViewRowEventArgs)处理TaxSaleGridView.RowDataBound
如果e.Row.RowType=DataControlRowType.DataRow,则
OPval=DirectCast(例如Row.DataItem、Data.DataRowView)(“其他包裹”).ToString()
选择Case OPval
这个案子不算什么
existsOtherParcel=“Y”
e、 行.单元格(3).背景色=System.Drawing.Color.Yellow
情况就是一切
existsOtherParcel=“N”
e、 行.单元格(3).背景色=System.Drawing.Color.YellowGreen
e、 Row.Cells(3).Text=TaxSaleGridView.Rows.Count
结束选择
如果结束
端接头
<%If existsOtherParcel = "Y" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="OtherParcelHyperLink" runat="server"
NavigateUrl='<%# Eval("OtherParcel", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br />
<asp:Label ID="notOnSale" runat="server" Text="Land is not on sale." Font-Bold="True"></asp:Label><br /><br />
<%ElseIf existsOtherParcel = "N" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="LocationMapHyperLink" runat="server"
NavigateUrl='<%# Eval("Property_ID", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br /><br />
<%End If%>
<asp:HyperLink ID="PRCHyperLink" runat="server"
NavigateUrl='<%# Eval("UnformattedParcelNumber", "http://URL/default.asp?sparcelno={0}&stemp=&dSearch=houseno&dreport=propcard&report=&dReportName=Property Card") %>'
Text="Property Record Card" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
我的HTML: <%If existsOtherParcel = "Y" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="OtherParcelHyperLink" runat="server"
NavigateUrl='<%# Eval("OtherParcel", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br />
<asp:Label ID="notOnSale" runat="server" Text="Land is not on sale." Font-Bold="True"></asp:Label><br /><br />
<%ElseIf existsOtherParcel = "N" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="LocationMapHyperLink" runat="server"
NavigateUrl='<%# Eval("Property_ID", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br /><br />
<%End If%>
<asp:HyperLink ID="PRCHyperLink" runat="server"
NavigateUrl='<%# Eval("UnformattedParcelNumber", "http://URL/default.asp?sparcelno={0}&stemp=&dSearch=houseno&dreport=propcard&report=&dReportName=Property Card") %>'
Text="Property Record Card" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
还有其他包裹吗
还有其他包裹吗
只有3次出现
OtherParcel
列将有一个值。。。其余的都是空白。我的目标是让参考资料
列中的位置图
超链接指向其他包裹
值(如果存在),或者如果不存在,则指向销售ID。但是,所有链接都指向销售ID,即使给定行中存在OtherParcel值正如您在gridview中看到的,“OtherParcel”列中的单元格正在按预期更改颜色
<%If existsOtherParcel = "Y" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="OtherParcelHyperLink" runat="server"
NavigateUrl='<%# Eval("OtherParcel", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br />
<asp:Label ID="notOnSale" runat="server" Text="Land is not on sale." Font-Bold="True"></asp:Label><br /><br />
<%ElseIf existsOtherParcel = "N" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="LocationMapHyperLink" runat="server"
NavigateUrl='<%# Eval("Property_ID", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br /><br />
<%End If%>
<asp:HyperLink ID="PRCHyperLink" runat="server"
NavigateUrl='<%# Eval("UnformattedParcelNumber", "http://URL/default.asp?sparcelno={0}&stemp=&dSearch=houseno&dreport=propcard&report=&dReportName=Property Card") %>'
Text="Property Record Card" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
我可能做错了什么 您不妨在代码隐藏中完成这一切:
<%If existsOtherParcel = "Y" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="OtherParcelHyperLink" runat="server"
NavigateUrl='<%# Eval("OtherParcel", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br />
<asp:Label ID="notOnSale" runat="server" Text="Land is not on sale." Font-Bold="True"></asp:Label><br /><br />
<%ElseIf existsOtherParcel = "N" Then%>
Other Parcel Exists? <%Response.Write(existsOtherParcel)%><br /><br />
<asp:HyperLink ID="LocationMapHyperLink" runat="server"
NavigateUrl='<%# Eval("Property_ID", "http://URL/index.html?parcel={0}") %>'
Text="Location Map" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink><br /><br />
<%End If%>
<asp:HyperLink ID="PRCHyperLink" runat="server"
NavigateUrl='<%# Eval("UnformattedParcelNumber", "http://URL/default.asp?sparcelno={0}&stemp=&dSearch=houseno&dreport=propcard&report=&dReportName=Property Card") %>'
Text="Property Record Card" Target="_blank" onclick="javascript:window.open(this.href, '','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=20,top=20');">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Select Case OPval
Case Is <> Nothing
existsOtherParcel = "Y"
e.Row.Cells(3).BackColor = System.Drawing.Color.Yellow
OtherParcelHyperLink.NavigateUrl = String.Format("http://URL/index.html?parcel={0}", OtherParcel)
Case Is = Nothing
existsOtherParcel = "N"
e.Row.Cells(3).BackColor = System.Drawing.Color.YellowGreen
e.Row.Cells(3).Text = TaxSaleGridView.Rows.Count
LocationMapHyperLink.NavigateUrl = String.Format("http://URL/index.html?parcel={0}", Property_ID)
End Select
选择Case OPval
这个案子不算什么
existsOtherParcel=“Y”
e、 行.单元格(3).背景色=System.Drawing.Color.Yellow
OtherParcelHyperLink.NavigateUrl=String.Format(“http://URL/index.html?parcel={0}”,其他包裹)
情况就是一切
existsOtherParcel=“N”
e、 行.单元格(3).背景色=System.Drawing.Color.YellowGreen
e、 Row.Cells(3).Text=TaxSaleGridView.Rows.Count
LocationMapHyperLink.NavigateUrl=String.Format(“http://URL/index.html?parcel={0},属性(ID)
结束选择
不是一个完整的答案,而是一些需要检查的东西。首先,在我看来opval将永远是空的,因为它被转换为一个字符串,因此存在,所以这个包将永远是“Y”。然而,我认为当事件被捕获时,行已经被渲染,因此对您的现有包执行操作已经很晚了。我认为您需要将URL更改应用到已经渲染的行,就像您对颜色所做的一样。因此,您是说我应该在代码中将[NavigateUrl]值设置为“OtherParcel”或“Property_ID”?是的。不过请更改您的案例-您应该与空字符串进行比较,而不是什么都不比较。我在第一个案例中添加了“OtherParcelHyperLink.NavigateUrl”部分,但出现以下错误:“OtherParcelHyperLink未声明。由于其保护级别,它可能无法访问。”好的,Intellisense正在识别“OtherParcelHyperLink”现在。。。但是当我运行它时,我得到了这个错误:“对象引用未设置为对象的实例。”@jschmidt奇怪,它不应该为null