Skip to content

Show `HyperLink`

Chevy Mark Sunderland

Asked Apr 10, 2012, 1:53 AM EDT4 answers
Share
LinkedInX
Hi there, I hope your appreciated help.

First of all I must say that I am a newbie when it comes to net language.

This is my problem.

I want to show `HyperLink3` enabled when the Bind("myState") is equal to `validate` and show `HyperLink3` desabled when the Bind("myState") is equal to `not validate`.

If you have link for similar task, please give it me.

Can you help me? thank you in advance.
Your help would be very appreciated

Thanks for your time and hints

<asp:TemplateField HeaderText="myState" SortExpression="myState">
<ItemTemplate>
<asp:Label ID="Label1" Text='<%# Eval("myState") %>' Runat="Server"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="myState" Runat="Server"
DataSourceID="SqlDataSource2"
DataTextField="myState"
DataValueField="myState"
SelectedValue='<%# Bind("myState") %>'
Font-Size="8pt"/>
</EditItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="Link" SortExpression="Link">
<ItemTemplate>
<asp:Panel ID="Panel3" Runat="Server">
<asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%# Eval("Link") %>' />
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Senthilkumar
    0
    Hi,

    You need to write the onrowdatabound event to the grid.

    TypeScript
     OnRowDataBound="gvCustomers_RowDataBound" in the grid.
    
    
    
    
    You need to find the control for every row and need to enable/disable the hyper link.
    protected void gvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink HyperLink3 = (HyperLink)e.Row.FindControl("HyperLink3");
                DropDownList ddlState = (DropDownList)e.Row.FindControl("myState");
    
    
                if (ddlState.SelectedIndex >= 0)
                {
                    if (ddlState.SelectedItem.Value == "validate")
                    {
                        HyperLink3.Enabled  = true;
                    }
                    else if (ddlState.SelectedItem.Value == "not validate")
                    {
                        HyperLink3.Enabled  = false;
                    }
    
    
    
    
                }
            }
        }

    Hope this will help you.
    0
  • 0
    Hello Senthilkumar !

    I'd appreciate your help so very much.

    Unfortunately your suggestion does not work the NavigateUrl='<%# Eval("Link") %>' is always enable when `myState` is `validate` or not.

    Thanks for your time and hints.

    protected void gvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    HyperLink HyperLink3 = (HyperLink)e.Row.FindControl("HyperLink3");
    DropDownList ddlState = (DropDownList)e.Row.FindControl("myState");

    if (ddlState.SelectedIndex >= 0)
    {
    if (ddlState.SelectedItem.Value == "validate")
    {
    HyperLink3.Enabled = true;
    }
    else if (ddlState.SelectedItem.Value == "not validate")
    {
    HyperLink3.Enabled = false;
    }


    }
    }
    }



    <asp:TemplateField HeaderText="myState" SortExpression="myState">
    <ItemTemplate>
    <asp:Label ID="Label1" Text='<%# Eval("myState") %>' Runat="Server"/>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList id="myState" Runat="Server"
    DataSourceID="SqlDataSource2"
    DataTextField="myState"
    DataValueField="myState"
    SelectedValue='<%# Bind("myState") %>'
    Font-Size="8pt"/>
    </EditItemTemplate>
    </asp:TemplateField>


    <asp:TemplateField HeaderText="Link" SortExpression="Link">
    <ItemTemplate>
    <asp:Panel ID="Panel3" Runat="Server">
    <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%# Eval("Link") %>' />
    </asp:Panel>
    </ItemTemplate>
    </asp:TemplateField>
    0
  • Senthilkumar
    0
    Hi,

    You are right! I misunderstood the use case.

    That will find the rows while binding. That time it will not have the selected value in the drop down list.

    You need to write the event for while selecting in the drop down list. Enable the auto post back property. 

    See this thread having solution.

    http://forums.asp.net/t/1511012.aspx/1?Event+handler+of+Dropdownlist+inside+Gridview

    y
    ou need to change the logic slightly.
    0
  • 0
    I'm sorry but I don't understand the link...
    what is your suggestion?
    0