Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my gridview i have columns sno,sname,contactnumber,subject,edit,delete and active/inactive columns.In the active/inactive column we use image button .images for showing whether in the active mode for one image and inactive for another image.my requirement is when we click on active button it will chage to inactive/inactive to active images and the modified value will be stored into database.how can i do that ,can any one help me
Posted

 
Share this answer
 
Its pretty simple. GridView1_RowCommand can be used to serve your puspose. On click of Active image button in the gridview, identify the GridViewRow
ASP.NET
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
OnRowCommand = "GridView1_RowCommand">
 <columns> 
   <asp:templatefield>
        <itemtemplate>
         <asp:label runat="server" text="<%#Eval("SNo")%>" id="lblSNo" />
       </itemtemplate>
   </asp:templatefield>

   <asp:templatefield>
        <itemtemplate>
         <asp:imagebutton id="imgStatus" commandname="Update" runat="server" src="../Active.jpg" alt="Image" />
       </itemtemplate>
   </asp:templatefield>

 </columns> 

</asp:gridview>


C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int index = Convert.ToInt32(e.CommandArgument);
    GridViewRow gvRow = GridView1.Rows[index];  
    string sNo = gr.Cells[0].Text;
    bool isActive = true; // Check the image first, if it is active, set false ans send to database else set true and send to database.
    // For the above sNo. Either call stored procedure or inline query to update the database, set the status as active or inactive.
}


Hope this helps.
 
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