Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add the values of 'amt' column into a variable 'v_amt' when checkbox selected. In the same variable I want to minus the value when I deselect the checkbox.

Here is the prevailing code but I could not make the requirement into it.
C#
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
TextBox txtname = (TextBox)grdRow.FindControl("txtName");
TextBox txtlocation = (TextBox)grdRow.FindControl("txtLocation");
if (chkTest.Checked)
{
    txtname.ReadOnly = false;
    txtlocation.ReadOnly = false;
    txtname.ForeColor = System.Drawing.Color.Black;
    txtlocation.ForeColor = System.Drawing.Color.Black;

}
else
{
    txtname.ReadOnly = true;
    txtlocation.ReadOnly = true;
    txtname.ForeColor = System.Drawing.Color.Blue;
    txtlocation.ForeColor = System.Drawing.Color.Blue;
}


Can some one guide me.
Posted
Updated 9-Apr-13 23:58pm
v3
Comments
Karthik Harve 10-Apr-13 5:58am    
[Edit] pre tags added.

Add DataKeyNames property of gridview to the list and the following value of the particular row can be retrieved by the following code....


C#
int index = int.Parse(e.CommandArgument.ToString());
string value = grdView.DataKeys[index].Value.ToString().Trim();
 
Share this answer
 
v2
VB
Protected Sub chkAuth_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
       Dim chk As New CheckBox
       chk = sender
       If chk.Checked = True Then
           Dim gr As GridViewRow
           gr = CType(chk.Parent.Parent, GridViewRow)
           grdSample.Rows(gr.RowIndex).Cells(4).Text = i + 1
           grdSample.Rows(gr.RowIndex).Cells(5).Text = "Yes"
       Else
           Dim gr As GridViewRow
           gr = CType(chk.Parent.Parent, GridViewRow)
           grdSample.Rows(gr.RowIndex).Cells(4).Text = ""
           grdSample.Rows(gr.RowIndex).Cells(5).Text = ""
       End If
   End Sub


 
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