Gridview超链接值基于行值和列标题标识符

时间:2013-09-09 11:22:41

标签: asp.net vb.net gridview hyperlink

我在vb.net中有一个gridview,它提供了上周,当前周和下周的商业名称列表的性能值,如下所示:

LOB   W-1   W    W+1
--------------------
AMEX  10   15    30
PPR   11   12    14 
REM   12   11    10

我需要的是这个值是一个超链接,它根据业务名称和周打开另一个窗口以提供更多详细信息。例如,如果您想要进一步使用值15的AMEX和当前周(W),那么按下值15将打开一个新窗口,其中包含当前一周的AMEX信息。

我创建了gridview,但我无法弄清楚如何进行超链接。有什么想法吗?

见下面的代码。

<asp:DropDownList ID="DateSelection" runat="server" Height="21px" Width="134px" >
</asp:DropDownList>
&nbsp;<asp:Button ID="Button_Update" runat="server" Text="UPDATE" />
<br />
    <br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
    GridLines="None" ForeColor="#333333">
    <Columns>
        <asp:BoundField DataField="LOB" HeaderText="LOB" />
        <asp:BoundField DataField="W-1" HeaderText="W-1" />
        <asp:BoundField DataField="W" HeaderText="W" />
        <asp:BoundField DataField="W+1" HeaderText="W+1" />         
    </Columns>
</asp:GridView>

vb代码

    Dim dv_Groups As New System.Data.DataView
    Dim dt_Groups As New System.Data.DataTable

    dv_Groups = Group.Select(DataSourceSelectArguments.Empty)
    dt_Groups = dv_Groups.ToTable()

    Dim dv_Main As New System.Data.DataView
    Dim dt_Main As New System.Data.DataTable

    dv_Main = SQL_Main.Select(DataSourceSelectArguments.Empty)
    dt_Main = dv_Main.ToTable()

    Dim dt_Report As New DataTable()
    dt_Report.Columns.Add("LOB", Type.GetType("System.String"))
    dt_Report.Columns.Add("W-1", Type.GetType("System.String"))
    dt_Report.Columns.Add("W", Type.GetType("System.String"))
    dt_Report.Columns.Add("W+1", Type.GetType("System.String"))

    Dim FindRow() As DataRow
    Dim SearchText As String
    Dim DateS As Date
    Dim DateWeek As String
    DateS = DateSelection.SelectedItem.Text
    Dateweek = Format(DatePart(DateInterval.WeekOfYear, DateS)) 

    For i As Integer = 0 To dt_Groups.Rows.Count - 1
        dt_Report.Rows.Add()
        dt_Report.Rows(i)(0) = dt_Groups.Rows(i)(0)
        SearchText = "LOB like '" & Trim(dt_Report.Rows(i)(0)) & "%'  And DateWeek = '" & Dateweek - 1 & "' "
        FindRow = dt_Main.Select(SearchText)
        dt_Report.Rows(i)(1) = FindRow(0).Item("A_SVL").ToString
        SearchText = "LOB like '" & Trim(dt_Report.Rows(i)(0)) & "%'  And DateWeek = '" & Dateweek & "' "
        FindRow = dt_Main.Select(SearchText)
        dt_Report.Rows(i)(2) = FindRow(0).Item("A_SVL").ToString
        SearchText = "LOB like '" & Trim(dt_Report.Rows(i)(0)) & "%'  And DateWeek = '" & Dateweek + 1 & "' "
        FindRow = dt_Main.Select(SearchText)
        dt_Report.Rows(i)(3) = FindRow(0).Item("S_SVL").ToString
    Next

    GridView1.DataSource = dt_Report
    GridView1.DataBind()

非常感谢

1 个答案:

答案 0 :(得分:0)

您可以使用HyperLinkField或TemplateField添加指向gridview的链接,如下所示:

https://stackoverflow.com/a/8859655/849182