如何根据条件

时间:2015-09-28 14:51:06

标签: asp.net vb.net gridview

If Request("cid") = 15 'Hudson Health Plan
    e.Row.Cells(11).Text = "<A href='http://myintra1/checkfile.aspx?id=90' target='_blank'>Click here for participating providers and the provider participating location/s.  </a> <br/>" & e.Row.Cells(11).Text
End If
If Request("cid") = 57 Then 'Hudson Health Plan
    e.Row.Cells(11).Text = "<A href='http://myintra1/checkfile.aspx?id=23' target='_blank'>Click here for participating providers and the provider participating location/s.  </a> <br/>" & e.Row.Cells(11).Text
End If

The above code shows correctly...

enter image description here

If Request("cid") = 15 And e.Row.Cells(3).Text = "Y" Then   'Hudson Health Plan
    e.Row.Cells(11).Text = "<A href='http://myintra1/checkfile.aspx?id=90' target='_blank'>Click here for participating providers and the provider participating location/s.  </a> <br/>" & e.Row.Cells(11).Text
Else
    e.Row.Cells(11).Text = ""
End If
If Request("cid") = 57 And e.Row.Cells(3).Text = "Y" Then   'Health Plus Amerigroup/Empire BCBS
    e.Row.Cells(11).Text = "<A href='http://myintra1/checkfile.aspx?id=23' target='_blank'>Click here for participating providers and the provider participating location/s.  </a> <br/>" & e.Row.Cells(11).Text
Else
    e.Row.Cells(11).Text = ""
End If

The above code shows correctly but it does not concatenate the text like it did in the first section of code....

enter image description here

如果CID匹配且第三列为“Y”,如何解决问题,然后显示链接和文本。如果“CID”匹配且第三列为“N”,则根本不显示任何内容。

2 个答案:

答案 0 :(得分:4)

假设第二张图片是cid = 57,会发生的事情是先执行else,单元格获取空值,然后执行第二个then,并将链接连接到空,先前清算,价值。要解决所有问题,请使用elseif

If Request("cid") = 15 And e.Row.Cells(3).Text = "Y" Then   'Hudson Health Plan
    e.Row.Cells(11).Text = "<A href='http://myintra1/checkfile.aspx?id=90' target='_blank'>Click here for participating providers and the provider participating location/s.  </a> <br/>" & e.Row.Cells(11).Text
Elseif Request("cid") = 57 And e.Row.Cells(3).Text = "Y" Then   'Health Plus Amerigroup/Empire BCBS
    e.Row.Cells(11).Text = "<A href='http://myintra1/checkfile.aspx?id=23' target='_blank'>Click here for participating providers and the provider participating location/s.  </a> <br/>" & e.Row.Cells(11).Text
Else
    e.Row.Cells(11).Text = ""
End If

答案 1 :(得分:1)

如果条件是&#34; Y&#34;你只需要附加链接的单元格。在e.Row.Cells(3).Text

中得到满足

案例陈述可能是您最好的选择,因为您没有复杂的if ifif条件,所以它们更容易阅读。

If e.Row.Cells(3).Text = "Y" Then 

    Select case Request("cid")

        case 15
            e.Row.Cells(11).Text = "CID = 15 link " & e.Row.Cells(11).Text
        case 57
            e.Row.Cells(11).Text = "CID = 57 link " & e.Row.Cells(11).Text
        case else
            e.Row.Cells(11).Text = ""
    End Select

End If
相关问题