Click here to Skip to main content
15,063,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have a GridView bound to a SqlDataSource and would like to try and set the visibility of a LinkButton based on the value of column in that row for example:

If Column ACTION_STATUS is 12 (Closed) then I want to hide the LinkButton I know I should be able to use the LinkButton.Visible = false; to do this, but not sure how to check the value of ACTION_STATUS

I want to be able to handle all this in the code behind page too.

As ever any help would be most appreicated.

Thanks

Pete
Posted

Hi it's very simple where e.Row.Cells[0] is index of your ACTION_STATUS clumn
C#
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if ((Convert.ToInt32(e.Row.Cells[0].ToString()) == 12))
            {
                HyperLink hy = (HyperLink)e.Row.FindControl("HyperLink");
                hy.Visible = false;
            }
        }



Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
   
v2
Comments
Hiren solanki 28-Oct-10 10:15am
   
e.Row.cell["ACTION_STATUS"].Text == "12" FTFY :)
Sunasara Imdadhusen 28-Oct-10 10:16am
   
Please update
if (Convert.ToInt32(e.Row.cell["ACTION_STATUS"].Text) == 12)
codemagpie 28-Oct-10 10:22am
   
Hi Imdadhusen

I tried as you suggested but get a red underline under the cell entry and then the following error:

'System.Web.UI.WebControls.GridViewRow' does not contain a definition for 'cell' and no extension method 'cell' accepting a first argument of type 'System.Web.UI.WebControls.GridViewRow' could be found (are you missing a using directive or an assembly reference?)

I would appreciate if you could offer any further help.

Thanks for the speedy answer.

Pete
codemagpie 28-Oct-10 10:32am
   
Hi
Still getting the red underline with that, full error is below:

Error 20 'System.Web.UI.WebControls.GridViewRow' does not contain a definition for 'cell' and no extension method 'cell' accepting a first argument of type 'System.Web.UI.WebControls.GridViewRow' could be found (are you missing a using directive or an assembly reference?) C:\Connect\Connect Solution\Connect V1 Source\crm\addactions.aspx.cs 107 39 C:\...\Connect V1 Source\

HTH

Thanks again

Pete
Sunasara Imdadhusen 29-Oct-10 1:36am
   
This is syntax error because i didn't copy it from editor, i had written it directly in Answer box.
You should resolve the syntax error by yourself.

Anyway, Please find my updated reply
raju melveetilpurayil 29-Oct-10 17:13pm
   
good one
Hi,

First you need to find the link button is there in which column.

Then after finding,mention that cell no in row databound event as follows.


C#
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if ((Convert.ToInt32(e.Row.Cells[0].ToString()) == 12))
            {
                HyperLink hy = (HyperLink)e.Row.FindControl("HyperLink");
                hy.Visible = false;
            }
        }

If you are still getting error, please check code for index position of linkbutton cell or where you are calling row databound event of Gridview.
   
Comments
Sunasara Imdadhusen 29-Oct-10 5:45am
   
Great!!!
raju melveetilpurayil 29-Oct-10 17:12pm
   
good one
Gridview_RowDataBound(..)
{
if( e.Row.cell["ACTION_STATUS"].Text == 12)
{
((LinkButton)e.Row.FindControl("LinkButtoVisible = false;
}
}
   
hi,
Please Use Following Steps
1. make Change your sql query for ACTION_STATUS condition. use Case Switch for check condition. when value is 12 then return false

Case when ACTION_STATUS='12' Then 'false' else 'True' End as ACTION_STATUS

2. In Design View
<asp:HyperLink ID="hplUR" runat="server" Text='ur text' Enabled='<%# Eval("ACTION_STATUS")%>' ></asp:HyperLink>
no need to RowDataBound event for that.


:thumbsup:
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900