Creating Dynamic Hyperlink in GridView
-
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 ?
-
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 ?
-
Your html seems ok. %20 means url encoded space. Did you check the values in database? Is there any empty space in url?
-
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.
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!!
-
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!!
-
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..
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!!
-
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 ?
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"/>
-
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.