Question : hide FormView "delete" and "edit" button links  programmatically

Help!

I have a FormView with Paging and LinkButtons (edit, new, and delete) enabled.  I want a way to hide the "delete" and "edit" link buttons whenever certain query criteria is true.  Question, how to you find the "id" of the current formview data and use it to hide edit and delete?

some code:

...//.. some query connect statement omitted here
      if (myReader.Read())
            {
            string myTestColumn = myReader["someColumn"].ToString();
                    if (FormView1.CurrentMode == FormViewMode.ReadOnly)
                    {
                            if (myTestColumn == "someString")
                            {
                                show delete button link;
                        show edit button link;        
                            }
                            else
                            {
                                return;
                            }
                    }

Linkbutton on ASPX:
           
           
           

Answer : hide FormView "delete" and "edit" button links  programmatically

---> Question, how to you find the "id" of the current formview data and use it to hide edit and delete?

I think you do that inside FormView DataBound Event like below:

protected void FormView1_DataBound(object sender, EventArgs e)
    {
             if (FormView1.CurrentMode == FormViewMode.ReadOnly)
                    {
                         DataRowView drv = (DataRowView)FormView1.DataItem;
                        string myTestColumn = drv["someColumn"].ToString();
 
                            if (myTestColumn == "someString")
                            {
                                    LinkButton btnEdit = (LinkButton)FormView1.FindControl("EditLinkButton");
                                         if (btnEdit != null)
                                       {
                                             btnEdit.Visible = false
                                        }
                                //similarly your delete and other controls
                            }
                           
                    }
   
    }
Random Solutions  
 
programming4us programming4us