2
Answers

how to active & deactive in GridView

SIVA

SIVA

12y
3.4k
1
Dear All,

I have table with the following fields

Item ID, Item Name, Price, Active.

Here Active column contains only 0 or 1 ie.
1-Available
0-not available

Here I binded this table with Gridview with Active/Deactive link button in it.
with addition of it Edit & Delete also

Now my requirement is I need to show available items & unavailable items also in Gridview but unavailable items will be with some light color.. when i click Active/Deactive button it will be in unavailable format & Edit & Delete buttons will be in Disable mode, When user clicks again Active/Deactive button which will be in normal view & Edit & Delete buttons will be Enabled.

How can i do this?
Answers (2)
0
Senthilkumar
NA 15.2k 2.4m 12y
Hi,

For example,

<asp:gridview id="ContactsGridView" 
              datasourceid="ContactsSource"
              allowpaging="true" 
              autogeneratecolumns="false"
              onrowcommand="ContactsGridView_RowCommand"
              runat="server">

              <columns>
                <asp:buttonfield buttontype="Link" 
                  commandname="Add" 
                  text="Add"/>
                <asp:boundfield datafield="ContactID" 
                  headertext="Contact ID"/>
                <asp:boundfield datafield="FirstName" 
                  headertext="First Name"/> 
                <asp:boundfield datafield="LastName" 
                  headertext="Last Name"/>
              </columns>

            </asp:gridview>

the server side event is,

void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
    // If multiple buttons are used in a GridView control, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="Add")
    {
     LinkButton lbtnActive = (LinkButton) e.FindControl("lbtnActive");
        lbtnActive.Enabled = false;

       //If you want to set the color then
e.Row.BackColor;
        e.Row.ForeColor;
    }
  }    
Accepted
0
SIVA
NA 842 555.6k 12y
Hi, Its showing error message that does not contain definition for FindControl() Are you missing a using directive or assembly reference