Hello.
if someone could help on this problem please..

I have a griedView that renders books from a database.
In each line a DELETE/EDIT button is rendered.

I want when the user clicks the EDIT button, the CANCEL,UPDATE buttoms to appear and the EDIT buttton to become disabled..
I though of using the onclick event for the edit button along with the griedView Row for getting the appropriate button based on the row..
Set the Edit button's Enable property to false and the Visibility of the Cancel and Edit buttons to true.

However, it seems I can not change the properties even for the Edit button i get from the event handler..
I am missing something..

Here is the code...

protected void EditButton_Click(object sender, EventArgs e)
    {

        Button Sender =  (Button)sender;
        Sender.Text = "??"; //THIS CHANGE IS NOT APPLIED!! 
        
            
        //Button Sender =  (Button)sender;
        //GridViewRow grdRow = (GridViewRow)Sender.Parent.Parent;
      
                
        //Button btn = (Button)grdBooks.Rows[grdRow.RowIndex].Cells[1].FindControl("CancelButton");

    
    }


 

<asp:GridView
        id="grdBooks"
        DataSourceID="srcBooks"
        DataKeyNames="Product_ID"
         
        AutoGenerateColumns="false"
        CssClass="products"
        GridLines="none"
        Runat="server" OnRowCreated="grdBooks_RowCreated">
        
         <Columns>
         
         <asp:TemplateField>
          <ItemTemplate>
           
           
           
            <asp:Button  CausesValidation="false" ID="DeleteButton" CommandName="Delete" runat="server" Text="Delete" />
                 
            <asp:Button  CausesValidation="false" ID="EditButton" CommandName="Edit" runat="server" Text="Edit" OnClick="EditButton_Click" />    
            <asp:Button  CausesValidation="false" ID="CancelButton"  Enabled="false" Visible="true" CommandName="Cancel" runat="server" Text="Cancel" />  
            <asp:Button  CausesValidation="false" ID="UpdateButton"  Enabled="false" Visible="true" CommandName="Update" runat="server" Text="Update" />  
           
           
          </ItemTemplate>
       </asp:TemplateField>
         
        <%-- <asp:CommandField  ButtonType="Button"  ShowEditButton="true"/>--%>
         
        <asp:BoundField 
            DataField="ISBN" 
            ReadOnly="true"
            HeaderText="ISBN" />
        <asp:BoundField 
            DataField="Title"
            ReadOnly="true"
            HeaderText="Title" />
        <asp:BoundField 
            DataField="First_Name" 
            ReadOnly="true"
            HeaderText="First Name" />
        <asp:BoundField 
            DataField="Last_Name" 
            ReadOnly="true"
            HeaderText="Last Name" />   
         <asp:BoundField 
            DataField="Price" 
            HeaderText="Price" />
        <asp:BoundField 
            DataField="Quantity" 
            HeaderText="Quantity" />
                                  
        </Columns>
        
            
    </asp:GridView>

Hello.
if someone could help on this problem please..

I have a griedView that renders books from a database.
In each line a DELETE/EDIT button is rendered.

I want when the user clicks the EDIT button, the CANCEL,UPDATE buttoms to appear and the EDIT buttton to become disabled..
I though of using the onclick event for the edit button along with the griedView Row for getting the appropriate button based on the row..
Set the Edit button's Enable property to false and the Visibility of the Cancel and Edit buttons to true.

However, it seems I can not change the properties even for the Edit button i get from the event handler..
I am missing something..

Here is the code...

protected void EditButton_Click(object sender, EventArgs e)
    {

        Button Sender =  (Button)sender;
        Sender.Text = "??"; //THIS CHANGE IS NOT APPLIED!! 
        
            
        //Button Sender =  (Button)sender;
        //GridViewRow grdRow = (GridViewRow)Sender.Parent.Parent;
      
                
        //Button btn = (Button)grdBooks.Rows[grdRow.RowIndex].Cells[1].FindControl("CancelButton");

    
    }


 

<asp:GridView
        id="grdBooks"
        DataSourceID="srcBooks"
        DataKeyNames="Product_ID"
         
        AutoGenerateColumns="false"
        CssClass="products"
        GridLines="none"
        Runat="server" OnRowCreated="grdBooks_RowCreated">
        
         <Columns>
         
         <asp:TemplateField>
          <ItemTemplate>
           
           
           
            <asp:Button  CausesValidation="false" ID="DeleteButton" CommandName="Delete" runat="server" Text="Delete" />
                 
            <asp:Button  CausesValidation="false" ID="EditButton" CommandName="Edit" runat="server" Text="Edit" OnClick="EditButton_Click" />    
            <asp:Button  CausesValidation="false" ID="CancelButton"  Enabled="false" Visible="true" CommandName="Cancel" runat="server" Text="Cancel" />  
            <asp:Button  CausesValidation="false" ID="UpdateButton"  Enabled="false" Visible="true" CommandName="Update" runat="server" Text="Update" />  
           
           
          </ItemTemplate>
       </asp:TemplateField>
         
        <%-- <asp:CommandField  ButtonType="Button"  ShowEditButton="true"/>--%>
         
        <asp:BoundField 
            DataField="ISBN" 
            ReadOnly="true"
            HeaderText="ISBN" />
        <asp:BoundField 
            DataField="Title"
            ReadOnly="true"
            HeaderText="Title" />
        <asp:BoundField 
            DataField="First_Name" 
            ReadOnly="true"
            HeaderText="First Name" />
        <asp:BoundField 
            DataField="Last_Name" 
            ReadOnly="true"
            HeaderText="Last Name" />   
         <asp:BoundField 
            DataField="Price" 
            HeaderText="Price" />
        <asp:BoundField 
            DataField="Quantity" 
            HeaderText="Quantity" />
                                  
        </Columns>
        
            
    </asp:GridView>

hide edit button after you hit edit is an auto behaviour, pls. have a look at the sample code
aspx

<asp:GridView runat="server" ID="gvTest" AutoGenerateColumns="False" CssClass="gridStyle" >
   
    <Columns>
        <asp:CommandField ButtonType="Button" ShowEditButton="True" />
        <asp:TemplateField>
            <ItemTemplate>
                <%#Container.DataItemIndex + 1%>
            </ItemTemplate>
        
        </asp:TemplateField>
        <asp:TemplateField HeaderText="ProductName" SortExpression="ProductName">
            
            <EditItemTemplate>
                <asp:DropDownList ID="ddlProduct" runat="server" Width="172px" DataValueField="ProductCode" DataTextField="ProductName"  >
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="ProductDescription" HeaderText="ProductDesc" SortExpression="ProductDescription" />
    </Columns>
    
</asp:GridView>

aspx.vb (rowediting event)

Private Sub gvTest_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvTest.RowEditing
        Dim ddlProduct As DropDownList

        

        ddlProduct = CType(gvTest.Rows(e.NewEditIndex).FindControl("ddlProduct"), DropDownList)
        ' ddlProduct = CType(gvrow.FindControl("ddlProduct"), DropDownList)

       

        If Not IsNothing(ddlProduct) Then
            Dim ds1 As New ProductGridDS
            ds1 = _loadproduct()
            ddlProduct.DataSource = ds1.ProductGridInfo
            ddlProduct.DataTextField = "ProductName"
            ddlProduct.DataValueField = "ProductCode"
            ddlProduct.DataBind()
            ddlProduct.Items.Insert(0, "")
            ddlProduct.SelectedIndex = -1
        End If



        Dim ds As New ProductGridDS
        ds = Session("ds")
        With gvTest
            .EditIndex = e.NewEditIndex
            .DataSource = ds
            .DataBind()
        End With
    End Sub

pls. mark as solved if it helps you!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.