Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi!
below is the code of what i have tried so far
My database has a table called stages with IdStage, IdState
and one called states with IdState and Name (inProgress, inWaiting and Finished)

I need to update only one cell in a gridview at Take task button click. When i click that button the row must be colored red and the state cell must change its state to inProgress and the button must disappear.
I managed to color the row at button click but have no idea how to update the cell at the same time.. please help i'm kind of new at this.
Thank you and i hope i made myself clear with my question

What I have tried:

the aspx

ASP.NET
<asp:TemplateField HeaderText="Actions">
                    <ItemTemplate>
                    <asp:Button ID="btnTake" runat="server" Text="Take task" OnClick="btnTake_Click" />
                    </ItemTemplate>
                    </asp:TemplateField>


the aspx.cs

C#
protected void btnTake_Click(object sender, EventArgs e)
    {
           string sqlUpdateState = "update stages set IdState=1 where IdStage = ??  "; (don't know what i'm supposed to say here to change only the state of clicked row )
        
       
            DataTable dt = GetData(sqlUpdateState);
            gvActivities.DataSource = dt;
       
        
            Button btnTake = (Button)sender;
            GridViewRow row = (GridViewRow)btnTake.NamingContainer;

            row.BackColor = System.Drawing.Color.Red;
            btnTake.Visible = false;
  }
Posted
Comments
Herman<T>.Instance 16-Dec-16 7:40am    
Have you set DataKeyNames in the Grid?
Member 12869977 16-Dec-16 8:01am    
yes i did that

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