Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a conditional hyperlink in grid
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01575963
Message ID:
01576086
Views:
54
>I quick google search turned this up.
>http://forums.asp.net/t/1186583.aspx/1

This got me in the neighborhood but I'm still having trouble changing the enabled property.

Here is what that site recommended:
protected void grdOpenItems_PreRender(object sender, EventArgs e)
{
   foreach (GridViewRow row in grdOpenItems.Rows)
   {
       if (row.RowType == DataControlRowType.DataRow)
       {
           HyperLink hl = (HyperLink)row.Cells[9].Controls[0]; // 9 is the hyperlink column index
           if (hl.Text = "Reserved")
           {
               hl.Enabled = false;
           }
           if (hl.Text = "Available")
           {
               hl.Enabled = true;
           }
       }
   }
}
This does not work because the Controls collection is empty. The following does not generate an error but it doesn't disable the link or the column, either:
    protected void grdOpenItems_PreRender(object sender, EventArgs e)
    {
        foreach (GridViewRow row in grdOpenItems.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                string sCategory = row.Cells[9].Text;
                if (sCategory == "C" || sCategory == "E")
                {
                    row.Cells[9].Enabled = false;
                }
                else
                {
                    row.Cells[9].Enabled = true;
                }
            }
        }
    }
So close. . . Any suggestions as to what to try next?

Thanks for getting me this far.
Linda Harmes
HiBit Technologies, Inc.
Previous
Reply
Map
View

Click here to load this message in the networking platform