Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DATE O.NO VEHICLE NO PARTICULARS QTY RATE AMOUNT(Rs)
04/07/2014 9 gj656 DIESEL 8 44 352
04/07/2014 7 gj656 DIESEL 3 44 132
04/07/2014 8 hj565 PETROL 2 60 120

This is my Report here i want subtotal vehicleno wise.
So how i add a new row in gridview to find subtotal vehicle no wise????


query = "select transdate,orderno,vehicleno,oiltype,qty,price,amount from [transaction] where custid=" + int.Parse(lblid.Text.Trim()) + "and orderno in (" + slipall.ToString() + ") and invoicestatus='true' order by vehicleno,transdate";
cmd = new SqlCommand(query, con);
// SqlCommand cmd = new SqlCommand("select * from [transaction]", con);
SqlDataReader reader1 = cmd.ExecuteReader();


DataRow nr = dt.NewRow();
if (reader1.Read())
{

DataRow dr = dt.NewRow();
nextno = reader1["vehicleno"].ToString();
afterno = reader1["vehicleno"].ToString();
amt = reader1["amount"].ToString();

dr["DATE"]= reader1["transdate"].ToString();
dr["O.NO"] = reader1["orderno"].ToString();
dr["VEHICLE NO"] = reader1["vehicleno"].ToString();
dr["PARTICULARS"]= reader1["oiltype"].ToString();
dr["QTY"]= reader1["qty"].ToString();
dr["RATE"] = reader1["price"].ToString();
dr["AMOUNT(Rs)"] = reader1["amount"].ToString();
dt.DefaultView.Sort = "VEHICLE NO";


dt.Rows.Add(dr);
if (preVno == afterno)
{
IsSubTotalRowNeedToAdd = true;

}
else
{
IsSubTotalRowNeedToAdd = false;
}
preVno = afterno;
}





if (IsSubTotalRowNeedToAdd == true)
{
dt.Rows.Add(nr);
prevtot = prevtot + Double.Parse(amt);
nr[0] = prevtot;
}
else
{

nr[0] = 0;
prevtot = 0;
}
//}


GridView1.DataSource = reader1;
GridView1.DataBind();
reader1.Close();

This is how i am retrieving data from database in this code a new row is added on the top position i want new row below the vehicles of same no so please help me to get this....
Posted
Updated 7-Apr-14 20:07pm
v2

1 solution

Hello,

following link might help you with your requirements,

http://www.c-sharpcorner.com/UploadFile/e06010/grouping-in-Asp-Net-gridview/[^]

Thanks,
Hitesh Varde
 
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