views:

288

answers:

2

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 buttons 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...

enter code here

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>
A: 

After the event is handled, the page probably reloads and resets the original text.

Maybe you could use JavaScript to do what you need.

GoodEnough
Thank you very much for replying. Indeed,the page is reloading..maybe the fact that the button is within the template in the Griedview results in reseting the original text.. If that is the case,is there a way to overcome this default behavior?..since when i update a button that is outside of the griedview it works perfeclty fine.
Nikos
A: 

Ok, it's very simple after all, there is this beautiful tag within the GridView that does exactly what i want.. Thanks for viewing, hope this post helps more niewbies..

<EditItemTemplate>
        <asp:Button  CausesValidation="false" ID="CancelButton"  CommandName="Cancel" runat="server" Text="Cancel" />  
        <asp:Button  CausesValidation="false" ID="UpdateButton"  CommandName="Update" runat="server" Text="Update" />  
</EditItemTemplate>
Nikos