Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Creating Dynamic Hyperlink in GridView

Creating Dynamic Hyperlink in GridView

Scheduled Pinned Locked Moved ASP.NET
databasesql-servercomsysadmindocker
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maxdd 7
    wrote on last edited by
    #1

    I have one field of Gridview populated from a DB (MS SQL Server) this way: One field is (for example) http://google.com

    <asp:TemplateField HeaderText="Link"
    SortExpression="Link">
    <ItemTemplate>

    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "URL") %>'  DataNavigateUrlFields="URL" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "URL") %>' />
    
    
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="URL" runat="server" 
                 Text='<%#Bind("URL") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="URL" runat="server" width="65px">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
    

    The problem is, when I click the http://google.com field, I go to http://google.com%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\%20%20%20%20%20%20%20%20%20%20(...) 20 is the ID of the field.. What am I doing wrong ?

    K L 2 Replies Last reply
    0
    • M Maxdd 7

      I have one field of Gridview populated from a DB (MS SQL Server) this way: One field is (for example) http://google.com

      <asp:TemplateField HeaderText="Link"
      SortExpression="Link">
      <ItemTemplate>

      <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "URL") %>'  DataNavigateUrlFields="URL" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "URL") %>' />
      
      
      </ItemTemplate>
      <EditItemTemplate>
      <asp:TextBox ID="URL" runat="server" 
                   Text='<%#Bind("URL") %>'>
      </asp:TextBox>
      </EditItemTemplate>
      <FooterTemplate>
      <asp:TextBox ID="URL" runat="server" width="65px">
      </asp:TextBox>
      </FooterTemplate>
      </asp:TemplateField>
      

      The problem is, when I click the http://google.com field, I go to http://google.com%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\%20%20%20%20%20%20%20%20%20%20(...) 20 is the ID of the field.. What am I doing wrong ?

      K Offline
      K Offline
      Kannan Ar
      wrote on last edited by
      #2

      Your html seems ok. %20 means url encoded space. Did you check the values in database? Is there any empty space in url?

      M 1 Reply Last reply
      0
      • K Kannan Ar

        Your html seems ok. %20 means url encoded space. Did you check the values in database? Is there any empty space in url?

        M Offline
        M Offline
        Maxdd 7
        wrote on last edited by
        #3

        Well, the field in the table of DB is char(100).. (MS SQL Server 2005) Maybe if I use VARCHAR I solve the problem? Not with my pc right now to test.

        _ M 2 Replies Last reply
        0
        • M Maxdd 7

          Well, the field in the table of DB is char(100).. (MS SQL Server 2005) Maybe if I use VARCHAR I solve the problem? Not with my pc right now to test.

          _ Offline
          _ Offline
          _Damian S_
          wrote on last edited by
          #4

          Trim the results... removes leading and trailing spaces . ;-)

          I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

          M 1 Reply Last reply
          0
          • _ _Damian S_

            Trim the results... removes leading and trailing spaces . ;-)

            I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

            M Offline
            M Offline
            Maxdd 7
            wrote on last edited by
            #5

            I honestly didnt understood what you just said about trimming the results but tomorrow I will try changing type of variable on DB and see if it solve the problem..

            _ 1 Reply Last reply
            0
            • M Maxdd 7

              I honestly didnt understood what you just said about trimming the results but tomorrow I will try changing type of variable on DB and see if it solve the problem..

              _ Offline
              _ Offline
              _Damian S_
              wrote on last edited by
              #6

              When you select the value from the database, use the TRIM() function to remove leading and trailing spaces. In SQL Server, this is ltrim(rtrim(FIELDNAME))

              I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

              1 Reply Last reply
              0
              • M Maxdd 7

                I have one field of Gridview populated from a DB (MS SQL Server) this way: One field is (for example) http://google.com

                <asp:TemplateField HeaderText="Link"
                SortExpression="Link">
                <ItemTemplate>

                <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "URL") %>'  DataNavigateUrlFields="URL" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "URL") %>' />
                
                
                </ItemTemplate>
                <EditItemTemplate>
                <asp:TextBox ID="URL" runat="server" 
                             Text='<%#Bind("URL") %>'>
                </asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="URL" runat="server" width="65px">
                </asp:TextBox>
                </FooterTemplate>
                </asp:TemplateField>
                

                The problem is, when I click the http://google.com field, I go to http://google.com%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\%20%20%20%20%20%20%20%20%20%20(...) 20 is the ID of the field.. What am I doing wrong ?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                hi Try using this way this is working for me..

                asp:HyperLinkField HeaderText ="Select Patient" DataNavigateUrlFields="patientId,maxAdmissionNo" DataTextField ="patientId" DataNavigateUrlFormatString ="ScheduleAppointment.aspx?&adMissionNo={1}&Patient_Id={0}" ItemStyle-HorizontalAlign ="Center" HeaderStyle-BackColor="#888888" HeaderStyle-ForeColor="white"/>

                1 Reply Last reply
                0
                • M Maxdd 7

                  Well, the field in the table of DB is char(100).. (MS SQL Server 2005) Maybe if I use VARCHAR I solve the problem? Not with my pc right now to test.

                  M Offline
                  M Offline
                  Maxdd 7
                  wrote on last edited by
                  #8

                  That's exactly what I said... Using VARCHAR everything works fine! So many time wasted... Thanks for your help!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups