Re: Template field and hyperlink

Discussion in 'ASP .Net' started by Alexey Smirnov, May 31, 2009.

  1. On May 21, 5:51 pm, JJ297 <> wrote:
    > Help!!!  I can't seem to get this to work  Plese take a look and tell
    > me what I'm doing wrong.
    >
    > I have a gridview and need to pass several parameters (3 of them) to
    > the next page when you click on the hyperlink.
    >
    > Here's my Gridview:
    >
    > <asp:GridView ID="GridView1" runat="server"
    > AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
    > Width="379px" AllowSorting="True">
    >                             <Columns>
    >                                 <asp:TemplateField>
    >                                     <ItemTemplate>
    >            <asp:HyperLink ID="HyperLink1" runat="server"
    > NavigateUrl='<%# Eval("Area", "Area.aspx?Area={0}&Period=" &
    > Request.QueryString("Period")) %>'>
    >
    > </asp:HyperLink>
    > </ItemTemplate>
    > </asp:TemplateField>
    >
    > <asp:BoundField DataField="totc" HeaderText="Diaries Cleared"
    > ReadOnly="True" SortExpression="totc" />
    >
    > <asp:BoundField DataField="totm" HeaderText="Cleared W/I 90 Days"
    > ReadOnly="True" SortExpression="totm" />
    >
    > <asp:BoundField DataField="perc" HeaderText="Percent W/I 90 Days"
    > ReadOnly="True" SortExpression="perc" />
    > </Columns>
    > </asp:GridView>
    >
    > Here's the vb.aspx page
    >
    >     Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal
    > e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    > GridView1.RowDataBound
    >
    >         Dim txt As String = e.Row.Cells(0).Text 'get the current text
    >         If e.Row.RowType = DataControlRowType.DataRow Then
    >             If e.Row.Cells(0).Text = "Area" Then
    >                 Dim hl As HyperLink = TryCast(e.Row.FindControl
    > ("HyperLink1"), HyperLink)
    >
    >                 If txt = "01" Or txt = "02" Or txt = "03" Or txt =
    > "04" Or txt = "05" Or txt = "06" Or txt = "07" Or txt = "08" Or txt =
    > "09" Then
    >                     hl.NavigateUrl = "area.aspx?area=" &
    > Request.QueryString("area") & "&" & "period" & "=" &
    > Request.QueryString("bgndt") & "&" & "Enddt" & "=" &
    > Request.QueryString("Enddt")
    >                 End If
    >             End If
    >         End If
    >     End Sub


    The first problem I see is in asp:HyperLink markup - you don't set the
    Text property of the control and you can't see it. You can't also use

    Dim txt As String = e.Row.Cells(0).Text

    because this always returns no value - your Cells(0) has defined
    ItemTemplate and only one control in it - asp:HyperLink. e.Row.Cells
    (0).Text will only work when the cell has text in it (not a control).

    As second,

    If e.Row.Cells(0).Text = "Area" Then

    makes no sense to me. I think it is a typo:

    Dim txt As String = e.Row.Cells(0).Text
    ....
    If e.Row.Cells(0).Text = "Area" Then
    ....
    If txt = "01"

    txt can't be equal to "Area" and "01" in the same time

    If you tried to check if name of the column is "Area" then it is also
    wrong - according to your markup

    <asp:TemplateField>
    <ItemTemplate>
    asp:HyperLink ....

    .....

    is always first column of the grid.
    Alexey Smirnov, May 31, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. davetichenor
    Replies:
    1
    Views:
    808
    Eliyahu Goldin
    Oct 30, 2006
  2. Ken
    Replies:
    1
    Views:
    363
    Alvin Bruney
    Aug 16, 2003
  3. Dave
    Replies:
    0
    Views:
    927
  4. Sound
    Replies:
    2
    Views:
    430
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    408
Loading...

Share This Page