Disable a control inside a gridview

Posted by saeed talaee on Stack Overflow See other posts from Stack Overflow or by saeed talaee
Published on 2012-10-20T21:53:38Z Indexed on 2012/10/21 5:02 UTC
Read the original article Hit count: 86

Filed under:

Hi i want to disable link-bottoms control in a grid view with the condition of a special value . for example if the count for a row become 0 ,the link bottom for that row should be invisible . what should i do? where should i write the code? here is cod that i write in row command grid view but it works only of i push the link bottom!! but i want to apply this cod to my page before loading. please guide me

    int idx = Convert.ToInt32(e.CommandArgument);

    idx = idx - (GridView1.PageSize * GridView1.PageIndex);

    int ID = (int)GridView1.DataKeys[idx].Value;
    string connStr = ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
    SqlConnection sqlconn = new SqlConnection(connStr);
    SqlCommand sqlcmd = new SqlCommand();
    sqlcmd = new SqlCommand("SELECT count(ID) FROM ReviwerArticle where ArticleID=@ArticleID", sqlconn);
    sqlcmd.Parameters.AddWithValue("@ArticleID", ID);

    sqlconn.Open();
    int count = ((int)sqlcmd.ExecuteScalar());

    sqlconn.Close();
    if (count == 0)
    {
                ((LinkButton)GridView1.Rows[idx].Cells[0].FindControl("LinkButton4") as LinkButton).Visible = false;

    }

© Stack Overflow or respective owner

Related posts about ASP.NET