datagrid conditional Hyperlink

Discussion in 'ASP .Net Datagrid Control' started by Brent Burkart, Apr 7, 2004.

  1. How do I set up a column in my datagrid which is blank when conditions are
    not met? I have certain records which contain additional information. I
    want a hyperlink for those records, but a blank for records without
    additional information.

    Any help is appreciated,

    Thanks,
    Brent
     
    Brent Burkart, Apr 7, 2004
    #1
    1. Advertising

  2. Brent Burkart

    Scott Guest

    Create a template column and in the control(s) for the template set the visibility of the anchor;
    something like:

    <asp:templatecolumn>
    <itemtemplate>
    <asp:Button runat="server" visible='<%# SomeKindOfExpression %>' />
    </itemtemplate>
    </asp:templatecolumn>

    So, for SomeKindOfExpression -- do something that returns a bool; this could be a method on your
    code behind class (make sure it's at least protected); or it could be a binding expression, like:
    DataBinder.Eval(Container, "DataItem.Flag").ToString().Equals("Value") --- or whatever else makes
    sense.

    Scott

    "Brent Burkart" <> wrote in message
    news:%...
    > How do I set up a column in my datagrid which is blank when conditions are
    > not met? I have certain records which contain additional information. I
    > want a hyperlink for those records, but a blank for records without
    > additional information.
    >
    > Any help is appreciated,
    >
    > Thanks,
    > Brent
    >
    >
     
    Scott, Apr 8, 2004
    #2
    1. Advertising

  3. Thanks Scott,

    But I am recieving this error in the html

    The active schema does not support the element 'asp:HyperlinkColumn'

    Here is the code

    <asp:templatecolumn>
    <itemtemplate>
    <asp:HyperlinkColumn Text="Click" Target="_blank"
    DataNavigateUrlField="Productid"
    DataNavigateUrlFormatString="shoppingcartsub.aspx?Productid={0}"
    HeaderText="Specs2" Visible='<%# DataBinder.Eval(Container.DataItem, "Show")
    %>' ></asp:HyperLinkColumn>
    </itemtemplate>
    </asp:templatecolumn>

    Thanks for your help

    "Scott" <> wrote in message
    news:...
    >
    > Create a template column and in the control(s) for the template set the

    visibility of the anchor;
    > something like:
    >
    > <asp:templatecolumn>
    > <itemtemplate>
    > <asp:Button runat="server" visible='<%# SomeKindOfExpression %>'

    />
    > </itemtemplate>
    > </asp:templatecolumn>
    >
    > So, for SomeKindOfExpression -- do something that returns a bool; this

    could be a method on your
    > code behind class (make sure it's at least protected); or it could be a

    binding expression, like:
    > DataBinder.Eval(Container, "DataItem.Flag").ToString().Equals("Value") ---

    or whatever else makes
    > sense.
    >
    > Scott
    >
    > "Brent Burkart" <> wrote in message
    > news:%...
    > > How do I set up a column in my datagrid which is blank when conditions

    are
    > > not met? I have certain records which contain additional information.

    I
    > > want a hyperlink for those records, but a blank for records without
    > > additional information.
    > >
    > > Any help is appreciated,
    > >
    > > Thanks,
    > > Brent
    > >
    > >

    >
    >
     
    Brent Burkart, Apr 8, 2004
    #3
  4. Brent Burkart

    Scott Guest

    Change HyperLinkColumn to HyperLink -- HyperLinkColumn is for a column of links in a DataGrid;
    what you are doing is creating a "template column" which are you inserting a HyperLink....

    Scott


    "Brent Burkart" <> wrote in message
    news:...
    > Thanks Scott,
    >
    > But I am recieving this error in the html
    >
    > The active schema does not support the element 'asp:HyperlinkColumn'
    >
    > Here is the code
    >
    > <asp:templatecolumn>
    > <itemtemplate>
    > <asp:HyperlinkColumn Text="Click" Target="_blank"
    > DataNavigateUrlField="Productid"
    > DataNavigateUrlFormatString="shoppingcartsub.aspx?Productid={0}"
    > HeaderText="Specs2" Visible='<%# DataBinder.Eval(Container.DataItem, "Show")
    > %>' ></asp:HyperLinkColumn>
    > </itemtemplate>
    > </asp:templatecolumn>
    >
    > Thanks for your help
    >
    > "Scott" <> wrote in message
    > news:...
    > >
    > > Create a template column and in the control(s) for the template set the

    > visibility of the anchor;
    > > something like:
    > >
    > > <asp:templatecolumn>
    > > <itemtemplate>
    > > <asp:Button runat="server" visible='<%# SomeKindOfExpression %>'

    > />
    > > </itemtemplate>
    > > </asp:templatecolumn>
    > >
    > > So, for SomeKindOfExpression -- do something that returns a bool; this

    > could be a method on your
    > > code behind class (make sure it's at least protected); or it could be a

    > binding expression, like:
    > > DataBinder.Eval(Container, "DataItem.Flag").ToString().Equals("Value") ---

    > or whatever else makes
    > > sense.
    > >
    > > Scott
    > >
    > > "Brent Burkart" <> wrote in message
    > > news:%...
    > > > How do I set up a column in my datagrid which is blank when conditions

    > are
    > > > not met? I have certain records which contain additional information.

    > I
    > > > want a hyperlink for those records, but a blank for records without
    > > > additional information.
    > > >
    > > > Any help is appreciated,
    > > >
    > > > Thanks,
    > > > Brent
    > > >
    > > >

    > >
    > >

    >
    >
     
    Scott, Apr 8, 2004
    #4
  5. Thanks Scott,

    When I change it from HyperLinkColumn to HyperLink, I lose the element of
    DataNavigateUrlField and DataNavigateUrlFormatString. I am not sure how to
    make the hyperlink work without those elements.

    Thanks for your help.
    Brent
    "Scott" <> wrote in message
    news:...
    >
    > Change HyperLinkColumn to HyperLink -- HyperLinkColumn is for a column

    of links in a DataGrid;
    > what you are doing is creating a "template column" which are you inserting

    a HyperLink....
    >
    > Scott
    >
    >
    > "Brent Burkart" <> wrote in message
    > news:...
    > > Thanks Scott,
    > >
    > > But I am recieving this error in the html
    > >
    > > The active schema does not support the element 'asp:HyperlinkColumn'
    > >
    > > Here is the code
    > >
    > > <asp:templatecolumn>
    > > <itemtemplate>
    > > <asp:HyperlinkColumn Text="Click" Target="_blank"
    > > DataNavigateUrlField="Productid"
    > > DataNavigateUrlFormatString="shoppingcartsub.aspx?Productid={0}"
    > > HeaderText="Specs2" Visible='<%# DataBinder.Eval(Container.DataItem,

    "Show")
    > > %>' ></asp:HyperLinkColumn>
    > > </itemtemplate>
    > > </asp:templatecolumn>
    > >
    > > Thanks for your help
    > >
    > > "Scott" <> wrote in message
    > > news:...
    > > >
    > > > Create a template column and in the control(s) for the template set

    the
    > > visibility of the anchor;
    > > > something like:
    > > >
    > > > <asp:templatecolumn>
    > > > <itemtemplate>
    > > > <asp:Button runat="server" visible='<%# SomeKindOfExpression

    %>'
    > > />
    > > > </itemtemplate>
    > > > </asp:templatecolumn>
    > > >
    > > > So, for SomeKindOfExpression -- do something that returns a bool;

    this
    > > could be a method on your
    > > > code behind class (make sure it's at least protected); or it could be

    a
    > > binding expression, like:
    > > > DataBinder.Eval(Container,

    "DataItem.Flag").ToString().Equals("Value") ---
    > > or whatever else makes
    > > > sense.
    > > >
    > > > Scott
    > > >
    > > > "Brent Burkart" <> wrote in message
    > > > news:%...
    > > > > How do I set up a column in my datagrid which is blank when

    conditions
    > > are
    > > > > not met? I have certain records which contain additional

    information.
    > > I
    > > > > want a hyperlink for those records, but a blank for records without
    > > > > additional information.
    > > > >
    > > > > Any help is appreciated,
    > > > >
    > > > > Thanks,
    > > > > Brent
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Brent Burkart, Apr 8, 2004
    #5
  6. Brent Burkart

    Scott Guest

    Just format it yourself:

    <asp:HyperLink ... NavigateUrl='<%# string.Format("shoppingcartsub.aspx?ProductId={0}",
    DataBinder.Eval(Container.DataItem, "ProductId")) %>' ../>

    You could do something like

    <asp:HyperLink ... NavigateUrl='<%# "shoppingcartsub.aspx?ProductId=" +
    DataBinder.Eval(Container.DataItem, "ProductId") %>'... />

    Scott

    "Brent Burkart" <> wrote in message
    news:...
    > Thanks Scott,
    >
    > When I change it from HyperLinkColumn to HyperLink, I lose the element of
    > DataNavigateUrlField and DataNavigateUrlFormatString. I am not sure how to
    > make the hyperlink work without those elements.
    >
    > Thanks for your help.
    > Brent
    > "Scott" <> wrote in message
    > news:...
    > >
    > > Change HyperLinkColumn to HyperLink -- HyperLinkColumn is for a column

    > of links in a DataGrid;
    > > what you are doing is creating a "template column" which are you inserting

    > a HyperLink....
    > >
    > > Scott
    > >
    > >
    > > "Brent Burkart" <> wrote in message
    > > news:...
    > > > Thanks Scott,
    > > >
    > > > But I am recieving this error in the html
    > > >
    > > > The active schema does not support the element 'asp:HyperlinkColumn'
    > > >
    > > > Here is the code
    > > >
    > > > <asp:templatecolumn>
    > > > <itemtemplate>
    > > > <asp:HyperlinkColumn Text="Click" Target="_blank"
    > > > DataNavigateUrlField="Productid"
    > > > DataNavigateUrlFormatString="shoppingcartsub.aspx?Productid={0}"
    > > > HeaderText="Specs2" Visible='<%# DataBinder.Eval(Container.DataItem,

    > "Show")
    > > > %>' ></asp:HyperLinkColumn>
    > > > </itemtemplate>
    > > > </asp:templatecolumn>
    > > >
    > > > Thanks for your help
    > > >
    > > > "Scott" <> wrote in message
    > > > news:...
    > > > >
    > > > > Create a template column and in the control(s) for the template set

    > the
    > > > visibility of the anchor;
    > > > > something like:
    > > > >
    > > > > <asp:templatecolumn>
    > > > > <itemtemplate>
    > > > > <asp:Button runat="server" visible='<%# SomeKindOfExpression

    > %>'
    > > > />
    > > > > </itemtemplate>
    > > > > </asp:templatecolumn>
    > > > >
    > > > > So, for SomeKindOfExpression -- do something that returns a bool;

    > this
    > > > could be a method on your
    > > > > code behind class (make sure it's at least protected); or it could be

    > a
    > > > binding expression, like:
    > > > > DataBinder.Eval(Container,

    > "DataItem.Flag").ToString().Equals("Value") ---
    > > > or whatever else makes
    > > > > sense.
    > > > >
    > > > > Scott
    > > > >
    > > > > "Brent Burkart" <> wrote in message
    > > > > news:%...
    > > > > > How do I set up a column in my datagrid which is blank when

    > conditions
    > > > are
    > > > > > not met? I have certain records which contain additional

    > information.
    > > > I
    > > > > > want a hyperlink for those records, but a blank for records without
    > > > > > additional information.
    > > > > >
    > > > > > Any help is appreciated,
    > > > > >
    > > > > > Thanks,
    > > > > > Brent
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Scott, Apr 8, 2004
    #6
  7. Thanks a lot Scott, Things are a go now. You have been very helpful.

    Brent
    "Scott" <> wrote in message
    news:...
    >
    > Just format it yourself:
    >
    > <asp:HyperLink ... NavigateUrl='<%#

    string.Format("shoppingcartsub.aspx?ProductId={0}",
    > DataBinder.Eval(Container.DataItem, "ProductId")) %>' ../>
    >
    > You could do something like
    >
    > <asp:HyperLink ... NavigateUrl='<%# "shoppingcartsub.aspx?ProductId=" +
    > DataBinder.Eval(Container.DataItem, "ProductId") %>'... />
    >
    > Scott
    >
    > "Brent Burkart" <> wrote in message
    > news:...
    > > Thanks Scott,
    > >
    > > When I change it from HyperLinkColumn to HyperLink, I lose the element

    of
    > > DataNavigateUrlField and DataNavigateUrlFormatString. I am not sure how

    to
    > > make the hyperlink work without those elements.
    > >
    > > Thanks for your help.
    > > Brent
    > > "Scott" <> wrote in message
    > > news:...
    > > >
    > > > Change HyperLinkColumn to HyperLink -- HyperLinkColumn is for a

    column
    > > of links in a DataGrid;
    > > > what you are doing is creating a "template column" which are you

    inserting
    > > a HyperLink....
    > > >
    > > > Scott
    > > >
    > > >
    > > > "Brent Burkart" <> wrote in message
    > > > news:...
    > > > > Thanks Scott,
    > > > >
    > > > > But I am recieving this error in the html
    > > > >
    > > > > The active schema does not support the element 'asp:HyperlinkColumn'
    > > > >
    > > > > Here is the code
    > > > >
    > > > > <asp:templatecolumn>
    > > > > <itemtemplate>
    > > > > <asp:HyperlinkColumn Text="Click" Target="_blank"
    > > > > DataNavigateUrlField="Productid"
    > > > > DataNavigateUrlFormatString="shoppingcartsub.aspx?Productid={0}"
    > > > > HeaderText="Specs2" Visible='<%# DataBinder.Eval(Container.DataItem,

    > > "Show")
    > > > > %>' ></asp:HyperLinkColumn>
    > > > > </itemtemplate>
    > > > > </asp:templatecolumn>
    > > > >
    > > > > Thanks for your help
    > > > >
    > > > > "Scott" <> wrote in message
    > > > > news:...
    > > > > >
    > > > > > Create a template column and in the control(s) for the template

    set
    > > the
    > > > > visibility of the anchor;
    > > > > > something like:
    > > > > >
    > > > > > <asp:templatecolumn>
    > > > > > <itemtemplate>
    > > > > > <asp:Button runat="server" visible='<%#

    SomeKindOfExpression
    > > %>'
    > > > > />
    > > > > > </itemtemplate>
    > > > > > </asp:templatecolumn>
    > > > > >
    > > > > > So, for SomeKindOfExpression -- do something that returns a bool;

    > > this
    > > > > could be a method on your
    > > > > > code behind class (make sure it's at least protected); or it could

    be
    > > a
    > > > > binding expression, like:
    > > > > > DataBinder.Eval(Container,

    > > "DataItem.Flag").ToString().Equals("Value") ---
    > > > > or whatever else makes
    > > > > > sense.
    > > > > >
    > > > > > Scott
    > > > > >
    > > > > > "Brent Burkart" <> wrote in message
    > > > > > news:%...
    > > > > > > How do I set up a column in my datagrid which is blank when

    > > conditions
    > > > > are
    > > > > > > not met? I have certain records which contain additional

    > > information.
    > > > > I
    > > > > > > want a hyperlink for those records, but a blank for records

    without
    > > > > > > additional information.
    > > > > > >
    > > > > > > Any help is appreciated,
    > > > > > >
    > > > > > > Thanks,
    > > > > > > Brent
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Brent Burkart, Apr 8, 2004
    #7
    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. chuckdfoster
    Replies:
    3
    Views:
    2,791
    Scott Allen
    Mar 9, 2005
  2. John Timney \(ASP.NET MVP\)

    Re: conditional hyperlink in datagrid

    John Timney \(ASP.NET MVP\), Jul 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    426
    John Timney \(ASP.NET MVP\)
    Jul 12, 2005
  3. Joe Fallon

    Re: conditional hyperlink in datagrid

    Joe Fallon, Jul 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,802
    Joe Fallon
    Jul 12, 2005
  4. davetichenor
    Replies:
    1
    Views:
    844
    Eliyahu Goldin
    Oct 30, 2006
  5. Dave
    Replies:
    0
    Views:
    957
Loading...

Share This Page