Click here to Skip to main content
15,743,429 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
help im trying to update a status of the request in a grid view by adding 2 buttons approve and disapprove button inside the gridview. pls help me how to do it. thanks

XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RequestNo"
           DataSourceID="SqlDataSource1">
           <columns>
               <asp:ButtonField CommandName="Update" Text="Approve" ButtonType="Button" />
               <asp:ButtonField ButtonType="Button" Text="Disapprove" />
               <asp:BoundField DataField="RequestNo" HeaderText="RequestNo" InsertVisible="False"
                   ReadOnly="True" SortExpression="RequestNo" />
               <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
               <asp:BoundField DataField="FullName" HeaderText="FullName" ReadOnly="True" SortExpression="FullName" />
               <asp:BoundField DataField="Position" HeaderText="Position" SortExpression="Position" />
               <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
               <asp:BoundField DataField="Section" HeaderText="Section" SortExpression="Section" />
               <asp:BoundField DataField="Employee" HeaderText="Employee" SortExpression="Employee" />
               <asp:BoundField DataField="Request" HeaderText="Request" SortExpression="Request" />
               <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
               <asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
               <asp:BoundField DataField="Account" HeaderText="Account" SortExpression="Account" />
           </columns>
Posted
Updated 26-Nov-13 22:38pm
v3

1 solution

Try this sample code..
XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RequestNo" OnRowCommand="GridView1_RowCommand">
            <Columns>
                <asp:ButtonField CommandName="Update" Text="Approve" ButtonType="Button" />
                <asp:ButtonField ButtonType="Button" Text="Disapprove" />
                <asp:BoundField DataField="RequestNo" HeaderText="RequestNo" InsertVisible="False"
                    ReadOnly="True" SortExpression="RequestNo" />
                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
                <asp:BoundField DataField="FullName" HeaderText="FullName" ReadOnly="True" SortExpression="FullName" />
                <asp:BoundField DataField="Position" HeaderText="Position" SortExpression="Position" />
                <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
                <asp:BoundField DataField="Section" HeaderText="Section" SortExpression="Section" />
                <asp:BoundField DataField="Employee" HeaderText="Employee" SortExpression="Employee" />
                <asp:BoundField DataField="Request" HeaderText="Request" SortExpression="Request" />
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
                <asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
                <asp:BoundField DataField="Account" HeaderText="Account" SortExpression="Account" />
            </Columns>
        </asp:GridView>


C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = GridView1.Rows[index];  // row which u have created..
                string requestNo = row.Cells[2].Text;
                // similarly u can get all the values of the row..
                // u can do ur stuff here...
            }

            if (e.CommandName == "") // other command names etc etc...
            { }
        }


This code will give you an idea ..

have a look at the belows links to better work through...
link
[^]
link
[^]
 
Share this answer
 
v2
Comments
Member 10428433 26-Nov-13 23:52pm    
how can i update only status of the request?
Karthik_Mahalingam 26-Nov-13 23:59pm    
Check this link for Codeproject guidelines.

http://www.codeproject.com/Articles/64628/Code-Project-Quick-Answers-FAQ#accept

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