Masood
Masood

Reputation: 1

How to Calculate using text box and two gridview items?

hope I can get some help as I am new to code writing. Trying to get the value of a text box and divide that by an item from gridview called "Divide" then deduct "Calc" value of the gridview from the outcome. Here is what I have but I know I am missing some declarations. I've spent a couple of days now trying to figure it out, I appreciate some help.

public partial class Links_Docs_AMIPD_ExtParts : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { length_txt.Focus();

}
protected void Calculate_Click(object sender, EventArgs e)
{
    if (ddPart.SelectedValue == "Sash Stop")
    {
        Label Length = this.FindControl("Length") as Label;
        Length.Text = "4";
    }
    else
    {
        GridViewRow row = GridViewAMI.SelectedRow;
        if (row != null)
        {
            int Divide = int.Parse(GridViewAMI.SelectedRow.Cells[1].Text);
            int Calc = int.Parse(GridViewAMI.SelectedRow.Cells[2].Text);
            int HW = Convert.ToInt32(length_txt.Text);
            Label Length = GridViewAMI.SelectedRow.FindControl("Label") as Label;
            Length.Text = ((HW / Divide) - Calc).ToString();

        }
     }
}

}

Upvotes: 0

Views: 153

Answers (1)

Rahul
Rahul

Reputation: 77934

Shouldn't you be getting the value of the selected row. So

int Divide = int.Parse(GridViewAMI.Columns[1].ToString());

should be

int Divide = int.Parse(GridViewAMI.SelectedRow.Cells[1].Text);

Upvotes: 0

Related Questions