4 Replies - 9697 Views - Last Post: 11 January 2013 - 08:21 PM

#1 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

datagrid, label, hyperlink, binding

Posted 10 January 2013 - 11:39 AM

Im a beginner at this asp.net dynamic data and have just been completing a few tutorials on youtube etc...

I was hoping maybe now to create a datagrid, (1) which binds labels to fields (exmaple) <asp:label runat=”server” ID=”abc” Text=’<%# Bind(“fieldname”) %>’>

(2) Also, where one of the columns had a hyperlink, which would bind to an external URL...so something instead of <asp:HyperLink ID="ChangePassword" runat="server" NavigateUrl="http://www.google.com" Target="_blank">Visit Google</asp:HyperLink>

I could have NavigateUrl=’http://bbcnews/<%# Bind(“id”) %>'which would then produce bbcnews/23, bbcnews/24, bbcnews/25 etc...

Could someone please point me in the right direction of where I can get a tutorial on this. Theres plenty of tutorials out there but I can't seem to find any relating to what I want to do.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: datagrid, label, hyperlink, binding

#2 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

Re: datagrid, label, hyperlink, binding

Posted 10 January 2013 - 12:25 PM

SO i've created a datagrid and linked it to one of my tables from my db. I then want to add a hyperlink which should bind to a column from the table
 <asp:DataGrid ID="DataGrid1" runat="server" DataSourceID="SqlDataSource1">
        </asp:DataGrid>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:holidaysConnectionString %>" 
            SelectCommand="SELECT [Name], [External_Link] FROM [Person]">
        </asp:SqlDataSource>
        <asp:HyperLink ID="hyperlink" runat="server" NavigateUrl='http://www.google.com/<%# Bind("External_Link")%>' Target="_blank">Visit Google</asp:HyperLink>

This isn't working can someone advise what I am doing wrong? I have 2 columns in my table, Name and External_Hyperlink, each row (inside the external_hyerplink column) contains the extension to a url so depending on which row was clicked i would get www.google.com/extension1, or www.google.com/extension2 etc.... but dont think I am anywhere near this, please help.

Thanks

This post has been edited by Xna4life: 10 January 2013 - 12:33 PM

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9418
  • View blog
  • Posts: 35,392
  • Joined: 12-June 08

Re: datagrid, label, hyperlink, binding

Posted 10 January 2013 - 12:30 PM

Let's not open duplicate topics, m'kay?
Was This Post Helpful? 0
  • +
  • -

#4 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

Re: datagrid, label, hyperlink, binding

Posted 10 January 2013 - 12:34 PM

View Postmodi123_1, on 10 January 2013 - 12:30 PM, said:

Let's not open duplicate topics, m'kay?


Thank you for the help Sir, much appreciated
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1058
  • View blog
  • Posts: 4,103
  • Joined: 02-July 08

Re: datagrid, label, hyperlink, binding

Posted 11 January 2013 - 08:21 PM

If your wanting that custom binding in the datagrid you create a TemplateColumn - which means setting AutoGenerateColumns to false and making BoundColumns for simple binding.

<asp:TemplateColumn HeaderText="Dose">
  <ItemTemplate >
    <asp:HyperLink ID="hyperlink" runat="server" NavigateUrl='http://www.google.com/<%# Bind("External_Link")%>' Target="_blank">Visit Google</asp:HyperLink>
  </ItemTemplate>
</asp:TemplateColumn>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1