Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a grid view, and inside that there's a edit button for each row, i want on button's click the values of row selected cell[1] value to store in a a label..
using asp.net c#
Posted

 
Share this answer
 
Comments
manishmns12 3-Feb-15 4:31am    
Thanks A lot...
i want to delete by doing the same..on clicking the button row should get deleted..
please help me out
santhu888 3-Feb-15 4:34am    
For deleting a row

http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/
manishmns12 3-Feb-15 4:37am    
Thanks alot but i want to use an Imagebutton and on clicking it the row should be deleted..can u please help me for it
here is code for delete button.

in aspx file we add code:
XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" EnableModelValidation="True"
            Font-Names="Tahoma" Font-Size="8pt" ForeColor="#333333" Width="100%" OnRowCommand="GridView1_RowCommand">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField DataField="No" HeaderText="No.">
                <HeaderStyle Width="100px" />
                <ItemStyle Width="100px" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="Delete">
                    <HeaderStyle Width="50px" />
                    <ItemStyle Width="50px" />
                    <ItemTemplate>
                        <asp:ImageButton runat="server" CommandName="delete" ImageUrl="~/images/delete.png" CommandArgument='<%#Eval("ID")%>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="CustName" HeaderText="Name" />
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        </asp:GridView>


And in code behind we add following code:

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("delete", StringComparison.OrdinalIgnoreCase))
            {
                //get id of record that you want
                var rowId = Convert.ToInt32(e.CommandArgument);
                //....
                GridView1.DataBind();//refresh data source
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900