How get total of textbox values on footer of Datagrid when click on RadioButton in asp.net

Posted by Cpatil1000 under ASP.NET on 5/8/2014 | Points: 10 | Views : 1301 | Status : [Member] | Replies : 1
Hi,
I have a Datagrid and in Datagrid I am using five radiobutton(Excellent, Best, Good, Average, Inferior) and on textbox (total marks) and lable marks which showing marks. Now I want when I click any radiobutton my calculation getting into total marks. These total marks must be added in footer of datagrid for grandsum. I am tying on my running webform but it is not getting total of datagrid footer. Only showing ‘0’..

protected void dgDetails_ItemDataBound(object source, DataGridItemEventArgs e)
{
TextBox tbTotal;

try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
MarksTotal += Convert.ToInt32(e.Item.Cells[2].Text);

tbTotal = (TextBox)e.Item.FindControl("tbTotal");

if (tbTotal.Text == string.Empty)
{
GrandTotal += 0;
}
else
{
GrandTotal = Convert.ToInt32(tbTotal.Text);
}
}

if (e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[1].Text = "Total";

e.Item.Cells[2].Text = MarksTotal.ToString();
e.Item.Cells[9].Text = GrandTotal.ToString();
}

}
catch (Exception ex)
{
throw ex;
}
}

protected void rbExcellent_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rbExcel;
RadioButton rbBst;
RadioButton rbGd;
RadioButton rbAvg;
RadioButton rbInf;

int lMarks;

TextBox tbTot;

try
{
foreach (DataGridItem item in this.dgDetails.Items)
{
rbExcel = (RadioButton)item.FindControl("rbExcellent");
rbBst = (RadioButton)item.FindControl("rbBest");
rbGd = (RadioButton)item.FindControl("rbGood");
rbAvg = (RadioButton)item.FindControl("rbAverage");
rbInf = (RadioButton)item.FindControl("rbInferior");

lMarks = Convert.ToInt32(item.Cells[2].Text);

tbTot = (TextBox)item.FindControl("tbTotal");

if (rbExcel.Checked == true)
{
tbTot.Text = Convert.ToString((lMarks * 100) / 100);

rbBst.Checked = false;
rbGd.Checked = false;
rbAvg.Checked = false;
rbInf.Checked = false;
}
}
}
catch (Exception ex)
{
throw ex;
}
}




Responses

Posted by: Preetimahawar on: 5/10/2014 [Member] Starter | Points: 25

Up
0
Down
hi.
can u just elaborate...
in each row of the grid u have 5 radio buttons and a textbox and a label
Do u have used radiobutton list in the grid column?
and on what basis u r doing ur calculations?
only when the user selects excellent option then total and grand totals are calculated?
and do the user enter marks in the textbox?


Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response