代码背后是错误的值传递给应用程序

时间:2014-05-22 14:32:39

标签: asp.net gridview

我试图根据列的值在gridview中显示特定的超链接。

这是我的GridView:
Image showing the GridView

代码背后:

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

End Sub

我的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列将具有值...其余为空白。我的目标是让Location Map列中的Reference Materials超链接指向OtherParcel值(如果存在),或者如果不存在则指向销售ID。但是,即使给定行存在OtherParcel值,所有链接都指向Sale ID。

正如您在gridview中看到的那样,&#34; OtherParcel&#34;列正在按预期更改颜色。

我可能做错了什么?

1 个答案:

答案 0 :(得分:0)

您可以在后面的代码中完成所有操作:

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