Hi,
I have a gridview that contains a TemplateField TextBox, labeled txtGvBox1, another Template Field that contains a checkbox labeled CheckBox1. Now within my form I have a TextBox labeled txtDelta that is not in the Gridview. This textbox contains a value that comes from the db. My goal is that when a user enters a value into the Gridview Textbox (txtGvBox1) and checks the checkbox, that that value is subtracted from the txtDelta textbox. Can someone give me an example of how I would do that. FYI I'm just learning to develop in C#.
Any help would be much appreciated
Loading
LarryPosted Apr 9, 2013, 1:17 AM
Current Inventory
CellPadding="3" GridLines="Vertical"
Width="900px" AllowPaging="True" AllowSorting="True" ShowFooter="True"
DataSourceID="SqlDataSource3">
ItemStyle-HorizontalAlign="Center" >
ItemStyle-HorizontalAlign="Center" >
AutoPostBack="True">
LarryPosted Apr 9, 2013, 12:59 AM
Vishal GilbilePosted Apr 9, 2013, 12:53 AM
You could easily do it through javascript or through code behind.
The Better approach would be to make use of CodeBehind. What you can do is try to provide a CommandName to your Checkbox inside Gridview and in the GridView_RowCommand event write the following code. Let's assume you provide a CommandName as "CheckMe"
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName.Equals("CheckMe"))
{
int rowIndex = ((GridViewRow)((CheckBox)sender).NamingContainer).RowIndex;
}
Pankaj RawatPosted Apr 9, 2013, 12:44 AM
Grid ID= "gridview1"
textBox 1 ID= "txtfirstnumber";
textbox 2 ID= "txtSecondNumber";
Protected Void chkSelected_CheckedChange(object sender,EventArgs)
{
Checkbox chknew=(Checkbox)sender;
GridviewRow newrow=(GridviewRow)chknew.NamingContainer;
int Row_ID=newrow.RowIndex;
TextBox txt1=(TextBox)gridview1.Rows[Row_ID].FindControl("txtfirstnumber);
TextBox txt2=(TextBox)gridview1.Rows[Row_ID].FindControl("txtSecondNumber);
/* IF Checked */
if(chknew.Checked==True)
{
int First_Number=Convert.ToInt32(txt1.Text);
int Second_Number=Convert.ToInt32(txt2.Text);
int Result=First_Number+Second_Number;
}
}