Answered by:
Modifying gridview cells with Manual DataSource

Question
-
User-1473011517 posted
Hello Experts I m new to this forum and also to ASP.NET. I'm building web app with several pages. Now I have problem with follow, I want to create such chart when web page loads or by other controls
Faculty PUC Sex SC ST C-I IIA IIB IIIA IIIB Gen Total Arts I Male 2 5 6 47 68 22 56 68 274 FeMale 5 9 6 98 9 55 1 33 0 II Male FeMale Commerce I Male FeMale II Male FeMale Science I Male FeMale II Male FeMale Wednesday, July 13, 2016 7:06 AM
Answers
-
User-1473011517 posted
Thank You Sir...@Nan Yu
I got my problem Solved
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, July 18, 2016 9:00 AM
All replies
-
User-1404113929 posted
hi,
vijay i am unable to understand your issue, can you explain it briefly.
thanks,
murali
Thursday, July 14, 2016 4:21 AM -
User1724605321 posted
Hi vijaypwr61,
Do you want to change/reload the gridview after a button click event or some other events ? Then you could rebuild the datasource of the gridview , and rebind the gridview like :
AuthorsGridView.DataSource = Your datasource; AuthorsGridView.DataBind();
If i misunderstand your requirement , please explain more about your requirements .
Best Regards,
Nan Yu
Thursday, July 14, 2016 5:39 AM -
User-1473011517 posted
Thank you Sir for viewing my thread.
I have created table and added rows to table then bind to GridView which in result getting clear GridView But I want to Merge the cells in which the Texts are same or data thats it. And I have fetched data from "accdb" by using "Count Query"
My Code
DataSet ds1 = new DataSet();
/*ARTS*/
Int32 CountAGenM = 0,CountAIIIBM = 0,CountAIIIAM = 0,CountAIIBM = 0,CountAIIAM = 0,CountACIM = 0,CountASCM = 0,CountASTM = 0,CountATotalM=0;
Int32 CountAGenF = 0, CountAIIIBF = 0, CountAIIIAF = 0, CountAIIBF = 0, CountAIIAF = 0, CountACIF = 0, CountASCF = 0, CountASTF = 0, CountATotalF = 0;
/*SCIENCE*/
Int32 CountSGenM = 0, CountSIIIBM = 0, CountSIIIAM = 0, CountSIIBM = 0, CountSIIAM = 0, CountSCIM = 0, CountSSCM = 0, CountSSTM = 0, CountSTotalM = 0;
Int32 CountSGenF = 0, CountSIIIBF = 0, CountSIIIAF = 0, CountSIIBF = 0, CountSIIAF = 0, CountSCIF = 0, CountSSCF = 0, CountSSTF = 0, CountSTotalF = 0;
/*COMMERCE*/
Int32 CountCGenM = 0, CountCIIIBM = 0, CountCIIIAM = 0, CountCIIBM = 0, CountCIIAM = 0, CountCCIM = 0, CountCSCM = 0, CountCSTM = 0, CountCTotalM = 0;
Int32 CountCGenF = 0, CountCIIIBF = 0, CountCIIIAF = 0, CountCIIBF = 0, CountCIIAF = 0, CountCCIF = 0, CountCSCF = 0, CountCSTF = 0, CountCTotalF = 0;/*Category TOTAL*/
Int32 TotalSC = 0, TotalST = 0, TotalCI = 0, TotalIIA = 0, TotalIIB = 0, TotalIIIA = 0, TotalIIIB = 0, TotalGen = 0, GrandTotal1=0, GrandTotal2=0;protected void StrYear_SelectedIndexChanged(object sender, EventArgs e)
{
/*ARTS*/
CallASCM(sender, e); CallASCF(sender, e);
CallASTM(sender, e); CallASTF(sender, e);
CallACIM(sender, e); CallACIF(sender, e);
CallAIIAM(sender, e); CallAIIAF(sender, e);
CallAIIBM(sender, e); CallAIIBF(sender, e);
CallAIIIAM(sender, e); CallAIIIAF(sender, e);
CallAIIIBM(sender, e); CallAIIIBF(sender, e);
CallAGenM(sender, e); CallAGenF(sender, e);
ArtsTotal(sender, e);
/*SCIENCE*/
CallSSCM(sender, e); CallSSCF(sender, e);
CallSSTM(sender, e); CallSSTF(sender, e);
CallSCIM(sender, e); CallSCIF(sender, e);
CallSIIAM(sender, e); CallSIIAF(sender, e);
CallSIIBM(sender, e); CallSIIBF(sender, e);
CallSIIIAM(sender, e); CallSIIIAF(sender, e);
CallSIIIBM(sender, e); CallSIIIBF(sender, e);
CallSGenM(sender, e); CallSGenF(sender, e);
ScienceTotal(sender, e);
/*COMMERCE*/
CallCSCM(sender, e); CallCSCF(sender, e);
CallCSTM(sender, e); CallCSTF(sender, e);
CallCCIM(sender, e); CallCCIF(sender, e);
CallCIIAM(sender, e); CallCIIAF(sender, e);
CallCIIBM(sender, e); CallCIIBF(sender, e);
CallCIIIAM(sender, e); CallCIIIAF(sender, e);
CallCIIIBM(sender, e); CallCIIIBF(sender, e);
CallCGenM(sender, e); CallCGenF(sender, e);
CommerceTotal(sender, e);/*CALLING GRAND TOTAL */
CallGrandTotal(sender, e);
DataTable dt1 = new DataTable();
dt1.Columns.Add("Faculty");
dt1.Columns.Add("PUC");
dt1.Columns.Add("Sex");
dt1.Columns.Add("SC");
dt1.Columns.Add("ST");
dt1.Columns.Add("C-I");
dt1.Columns.Add("IIA");
dt1.Columns.Add("IIB");
dt1.Columns.Add("IIIA");
dt1.Columns.Add("IIIB");
dt1.Columns.Add("Gen");
dt1.Columns.Add("Total");DataRow dr1 = dt1.NewRow();
DataRow dr2 = dt1.NewRow();
DataRow dr3 = dt1.NewRow();
DataRow dr4 = dt1.NewRow();
DataRow dr5 = dt1.NewRow();
DataRow dr6 = dt1.NewRow();
DataRow dr7 = dt1.NewRow();/*FIRST ROW*/
dr1["Faculty"] = "Arts";
dr1["PUC"] = "I";
dr1["Sex"] = "Female";
dr1["SC"] = Convert.ToString(CountASCF);
dr1["ST"] = Convert.ToString(CountASTF);
dr1["C-I"] = Convert.ToString(CountACIF);
dr1["IIA"] = Convert.ToString(CountAIIAF);
dr1["IIB"] = Convert.ToString(CountAIIBF);
dr1["IIIA"] = Convert.ToString(CountAIIIAF);
dr1["IIIB"] = Convert.ToString(CountAIIIBF);
dr1["Gen"] = Convert.ToString(CountAGenF);
dr1["Total"] = Convert.ToString(CountATotalF);
/*SECOND ROW*/
dr2["Faculty"] = "Arts";
dr2["PUC"] = "I";
dr2["Sex"] = "Male";
dr2["SC"] = Convert.ToString(CountASCM);
dr2["ST"] = Convert.ToString(CountASTM);
dr2["C-I"] = Convert.ToString(CountACIM);
dr2["IIA"] = Convert.ToString(CountAIIAM);
dr2["IIB"] = Convert.ToString(CountAIIBM);
dr2["IIIA"] = Convert.ToString(CountAIIIAM);
dr2["IIIB"] = Convert.ToString(CountAIIIBM);
dr2["Gen"] = Convert.ToString(CountAGenF);
dr2["Total"] = Convert.ToString(CountATotalM);
/*THIRD ROW*/
dr3["Faculty"] = "Commerce";
dr3["PUC"] = "I";
dr3["Sex"] = "Female";
dr3["SC"] = Convert.ToString(CountCSCF);
dr3["ST"] = Convert.ToString(CountCSTF);
dr3["C-I"] = Convert.ToString(CountCCIF);
dr3["IIA"] = Convert.ToString(CountCIIAF);
dr3["IIB"] = Convert.ToString(CountCIIBF);
dr3["IIIA"] = Convert.ToString(CountCIIIAF);
dr3["IIIB"] = Convert.ToString(CountCIIIBF);
dr3["Gen"] = Convert.ToString(CountCGenF);
dr3["Total"] = Convert.ToString(CountCTotalF);
/*FOURTH ROW*/
dr4["Faculty"] = "Commerce";
dr4["PUC"] = "I";
dr4["Sex"] = "Male";
dr4["SC"] = Convert.ToString(CountCSCM);
dr4["ST"] = Convert.ToString(CountCSTM);
dr4["C-I"] = Convert.ToString(CountCCIM);
dr4["IIA"] = Convert.ToString(CountCIIAM);
dr4["IIB"] = Convert.ToString(CountCIIBM);
dr4["IIIA"] = Convert.ToString(CountCIIIAM);
dr4["IIIB"] = Convert.ToString(CountCIIIBM);
dr4["Gen"] = Convert.ToString(CountCGenM);
dr4["Total"] = Convert.ToString(CountCTotalM);/*FIFTH ROW*/
dr5["Faculty"] = "Science";
dr5["PUC"] = "I";
dr5["Sex"] = "Female";
dr5["SC"] = Convert.ToString(CountSSCF);
dr5["ST"] = Convert.ToString(CountSSTF);
dr5["C-I"] = Convert.ToString(CountSCIF);
dr5["IIA"] = Convert.ToString(CountSIIAF);
dr5["IIB"] = Convert.ToString(CountSIIBF);
dr5["IIIA"] = Convert.ToString(CountSIIIAF);
dr5["IIIB"] = Convert.ToString(CountSIIIBF);
dr5["Gen"] = Convert.ToString(CountSGenF);
dr5["Total"] = Convert.ToString(CountSTotalF);
/*SIXTH ROW*/
dr6["Faculty"] = "Science";
dr6["PUC"] = "I";
dr6["Sex"] = "Male";
dr6["SC"] = Convert.ToString(CountSSCM);
dr6["ST"] = Convert.ToString(CountSSTM);
dr6["C-I"] = Convert.ToString(CountSCIM);
dr6["IIA"] = Convert.ToString(CountSIIAM);
dr6["IIB"] = Convert.ToString(CountSIIBM);
dr6["IIIA"] = Convert.ToString(CountSIIIAM);
dr6["IIIB"] = Convert.ToString(CountSIIIBM);
dr6["Gen"] = Convert.ToString(CountSGenM);
dr6["Total"] = Convert.ToString(CountSTotalM);
/*SEVENTH ROW*/
dr7["Faculty"] = "Total";
dr7["PUC"] = "---";
dr7["Sex"] = "---";
dr7["SC"] = Convert.ToString(TotalSC);
dr7["ST"] = Convert.ToString(TotalST);
dr7["C-I"] = Convert.ToString(TotalCI);
dr7["IIA"] = Convert.ToString(TotalIIA);
dr7["IIB"] = Convert.ToString(TotalIIB);
dr7["IIIA"] = Convert.ToString(TotalIIIA);
dr7["IIIB"] = Convert.ToString(TotalIIIB);
dr7["Gen"] = Convert.ToString(TotalGen);if (GrandTotal1 == GrandTotal2)
{
dr7["Total"] = Convert.ToString(GrandTotal1);
}
else
{
dr7["Total"] = "Error";
}
dt1.Rows.Add(dr1);
dt1.Rows.Add(dr2);
dt1.Rows.Add(dr3);
dt1.Rows.Add(dr4);
dt1.Rows.Add(dr5);
dt1.Rows.Add(dr6);
dt1.Rows.Add(dr7);
Gv1.DataSource = dt1;
Gv1.DataBind();
}
/*ARTS*/protected void CallASCM (object sender, EventArgs e)
{
OleDbCommand comscm = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='"+StrYear.SelectedValue.ToString()+"' AND Faculty='Arts' AND Category='SC' AND Sex='M'", con1);
con1.Open();
CountASCM = Convert.ToInt32(comscm.ExecuteScalar());
con1.Close();
}protected void CallASCF(object sender, EventArgs e)
{
OleDbCommand comscf = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='SC' AND Sex='F'", con1);
con1.Open();
CountASCF = Convert.ToInt32(comscf.ExecuteScalar());
con1.Close();
}protected void CallASTM(object sender, EventArgs e)
{
OleDbCommand comstm = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='ST' AND Sex='M'", con1);
con1.Open();
CountASTM = Convert.ToInt32(comstm.ExecuteScalar());
con1.Close();
}protected void CallASTF(object sender, EventArgs e)
{
OleDbCommand comstf = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='ST' AND Sex='F'", con1);
con1.Open();
CountASTF = Convert.ToInt32(comstf.ExecuteScalar());
con1.Close();
}protected void CallACIM(object sender, EventArgs e)
{
OleDbCommand comcim = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='C-I' AND Sex='M'", con1);
con1.Open();
CountACIM = Convert.ToInt32(comcim.ExecuteScalar());
con1.Close();
}protected void CallACIF(object sender, EventArgs e)
{
OleDbCommand comcif = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='C-I' AND Sex='F'", con1);
con1.Open();
CountACIF = Convert.ToInt32(comcif.ExecuteScalar());
con1.Close();
}
protected void CallAIIAM(object sender, EventArgs e)
{
OleDbCommand comIIAM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIA' AND Sex='M'", con1);
con1.Open();
CountAIIAM = Convert.ToInt32(comIIAM.ExecuteScalar());
con1.Close();
}protected void CallAIIAF(object sender, EventArgs e)
{
OleDbCommand comIIAF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIA' AND Sex='F'", con1);
con1.Open();
CountAIIAF = Convert.ToInt32(comIIAF.ExecuteScalar());
con1.Close();
}protected void CallAIIBM(object sender, EventArgs e)
{
OleDbCommand comIIBM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIB' AND Sex='M'", con1);
con1.Open();
CountAIIBM = Convert.ToInt32(comIIBM.ExecuteScalar());
con1.Close();
}protected void CallAIIBF(object sender, EventArgs e)
{
OleDbCommand comIIBF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIB' AND Sex='F'", con1);
con1.Open();
CountAIIBF = Convert.ToInt32(comIIBF.ExecuteScalar());
con1.Close();
}protected void CallAIIIAM(object sender, EventArgs e)
{
OleDbCommand comIIIAM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIIA' AND Sex='M'", con1);
con1.Open();
CountAIIIAM = Convert.ToInt32(comIIIAM.ExecuteScalar());
con1.Close();
}protected void CallAIIIAF(object sender, EventArgs e)
{
OleDbCommand comIIIAF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIIA' AND Sex='F'", con1);
con1.Open();
CountAIIIAF = Convert.ToInt32(comIIIAF.ExecuteScalar());
con1.Close();
}protected void CallAIIIBM(object sender, EventArgs e)
{
OleDbCommand comIIIBM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIIB' AND Sex='M'", con1);
con1.Open();
CountAIIIBM = Convert.ToInt32(comIIIBM.ExecuteScalar());
con1.Close();
}protected void CallAIIIBF(object sender, EventArgs e)
{
OleDbCommand comIIIBF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='IIIB' AND Sex='F'", con1);
con1.Open();
CountAIIIBF = Convert.ToInt32(comIIIBF.ExecuteScalar());
con1.Close();
}protected void CallAGenM(object sender, EventArgs e)
{
OleDbCommand comGenM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='Gen' AND Sex='M'", con1);
con1.Open();
CountAGenM = Convert.ToInt32(comGenM.ExecuteScalar());
con1.Close();
}protected void CallAGenF(object sender, EventArgs e)
{
OleDbCommand comGenF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Arts' AND Category='Gen' AND Sex='F'", con1);
con1.Open();
CountAGenF = Convert.ToInt32(comGenF.ExecuteScalar());
con1.Close();
}protected void ArtsTotal(object sender, EventArgs e)
{
CountATotalM = CountAGenM + CountAIIIBM + CountAIIIAM + CountAIIBM + CountAIIAM + CountACIM + CountASCM + CountASTM;
CountATotalF = CountAGenF + CountAIIIBF + CountAIIIAF + CountAIIBF + CountAIIAF + CountACIF + CountASCF + CountASTF;
}
/* SCIENCE*/protected void CallSSCM(object sender, EventArgs e)
{
OleDbCommand comscm = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='SC' AND Sex='M'", con1);
con1.Open();
CountSSCM = Convert.ToInt32(comscm.ExecuteScalar());
con1.Close();
}protected void CallSSCF(object sender, EventArgs e)
{
OleDbCommand comscf = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='SC' AND Sex='F'", con1);
con1.Open();
CountSSCF = Convert.ToInt32(comscf.ExecuteScalar());
con1.Close();
}protected void CallSSTM(object sender, EventArgs e)
{
OleDbCommand comstm = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='ST' AND Sex='M'", con1);
con1.Open();
CountSSTM = Convert.ToInt32(comstm.ExecuteScalar());
con1.Close();
}protected void CallSSTF(object sender, EventArgs e)
{
OleDbCommand comstf = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='ST' AND Sex='F'", con1);
con1.Open();
CountSSTF = Convert.ToInt32(comstf.ExecuteScalar());
con1.Close();
}protected void CallSCIM(object sender, EventArgs e)
{
OleDbCommand comcim = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='C-I' AND Sex='M'", con1);
con1.Open();
CountSCIM = Convert.ToInt32(comcim.ExecuteScalar());
con1.Close();
}protected void CallSCIF(object sender, EventArgs e)
{
OleDbCommand comcif = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='C-I' AND Sex='F'", con1);
con1.Open();
CountSCIF = Convert.ToInt32(comcif.ExecuteScalar());
con1.Close();
}protected void CallSIIAM(object sender, EventArgs e)
{
OleDbCommand comIIAM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIA' AND Sex='M'", con1);
con1.Open();
CountSIIAM = Convert.ToInt32(comIIAM.ExecuteScalar());
con1.Close();
}protected void CallSIIAF(object sender, EventArgs e)
{
OleDbCommand comIIAF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIA' AND Sex='F'", con1);
con1.Open();
CountSIIAF = Convert.ToInt32(comIIAF.ExecuteScalar());
con1.Close();
}protected void CallSIIBM(object sender, EventArgs e)
{
OleDbCommand comIIBM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIB' AND Sex='M'", con1);
con1.Open();
CountSIIBM = Convert.ToInt32(comIIBM.ExecuteScalar());
con1.Close();
}protected void CallSIIBF(object sender, EventArgs e)
{
OleDbCommand comIIBF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIB' AND Sex='F'", con1);
con1.Open();
CountSIIBF = Convert.ToInt32(comIIBF.ExecuteScalar());
con1.Close();
}protected void CallSIIIAM(object sender, EventArgs e)
{
OleDbCommand comIIIAM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIIA' AND Sex='M'", con1);
con1.Open();
CountSIIIAM = Convert.ToInt32(comIIIAM.ExecuteScalar());
con1.Close();
}protected void CallSIIIAF(object sender, EventArgs e)
{
OleDbCommand comIIIAF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIIA' AND Sex='F'", con1);
con1.Open();
CountSIIIAF = Convert.ToInt32(comIIIAF.ExecuteScalar());
con1.Close();
}protected void CallSIIIBM(object sender, EventArgs e)
{
OleDbCommand comIIIBM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIIB' AND Sex='M'", con1);
con1.Open();
CountSIIIBM = Convert.ToInt32(comIIIBM.ExecuteScalar());
con1.Close();
}protected void CallSIIIBF(object sender, EventArgs e)
{
OleDbCommand comIIIBF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='IIIB' AND Sex='F'", con1);
con1.Open();
CountSIIIBF = Convert.ToInt32(comIIIBF.ExecuteScalar());
con1.Close();
}protected void CallSGenM(object sender, EventArgs e)
{
OleDbCommand comGenM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='Gen' AND Sex='M'", con1);
con1.Open();
CountSGenM = Convert.ToInt32(comGenM.ExecuteScalar());
con1.Close();
}protected void CallSGenF(object sender, EventArgs e)
{
OleDbCommand comGenF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Science' AND Category='Gen' AND Sex='F'", con1);
con1.Open();
CountSGenF = Convert.ToInt32(comGenF.ExecuteScalar());
con1.Close();
}protected void ScienceTotal(object sender, EventArgs e)
{
CountSTotalM = CountSGenM + CountSIIIBM + CountSIIIAM + CountSIIBM + CountSIIAM + CountSCIM + CountSSCM + CountSSTM;
CountSTotalF = CountSGenF + CountSIIIBF + CountSIIIAF + CountSIIBF + CountSIIAF + CountSCIF + CountSSCF + CountSSTF;
}
/*COMMERCE*/protected void CallCSCM(object sender, EventArgs e)
{
OleDbCommand comscm = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='SC' AND Sex='M'", con1);
con1.Open();
CountCSCM = Convert.ToInt32(comscm.ExecuteScalar());
con1.Close();
}protected void CallCSCF(object sender, EventArgs e)
{
OleDbCommand comscf = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='SC' AND Sex='F'", con1);
con1.Open();
CountCSCF = Convert.ToInt32(comscf.ExecuteScalar());
con1.Close();
}protected void CallCSTM(object sender, EventArgs e)
{
OleDbCommand comstm = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='ST' AND Sex='M'", con1);
con1.Open();
CountCSTM = Convert.ToInt32(comstm.ExecuteScalar());
con1.Close();
}protected void CallCSTF(object sender, EventArgs e)
{
OleDbCommand comstf = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='ST' AND Sex='F'", con1);
con1.Open();
CountCSTF = Convert.ToInt32(comstf.ExecuteScalar());
con1.Close();
}protected void CallCCIM(object sender, EventArgs e)
{
OleDbCommand comcim = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='C-I' AND Sex='M'", con1);
con1.Open();
CountCCIM = Convert.ToInt32(comcim.ExecuteScalar());
con1.Close();
}protected void CallCCIF(object sender, EventArgs e)
{
OleDbCommand comcif = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='C-I' AND Sex='F'", con1);
con1.Open();
CountCCIF = Convert.ToInt32(comcif.ExecuteScalar());
con1.Close();
}protected void CallCIIAM(object sender, EventArgs e)
{
OleDbCommand comIIAM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIA' AND Sex='M'", con1);
con1.Open();
CountCIIAM = Convert.ToInt32(comIIAM.ExecuteScalar());
con1.Close();
}protected void CallCIIAF(object sender, EventArgs e)
{
OleDbCommand comIIAF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIA' AND Sex='F'", con1);
con1.Open();
CountCIIAF = Convert.ToInt32(comIIAF.ExecuteScalar());
con1.Close();
}protected void CallCIIBM(object sender, EventArgs e)
{
OleDbCommand comIIBM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIB' AND Sex='M'", con1);
con1.Open();
CountCIIBM = Convert.ToInt32(comIIBM.ExecuteScalar());
con1.Close();
}protected void CallCIIBF(object sender, EventArgs e)
{
OleDbCommand comIIBF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIB' AND Sex='F'", con1);
con1.Open();
CountCIIBF = Convert.ToInt32(comIIBF.ExecuteScalar());
con1.Close();
}protected void CallCIIIAM(object sender, EventArgs e)
{
OleDbCommand comIIIAM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIIA' AND Sex='M'", con1);
con1.Open();
CountCIIIAM = Convert.ToInt32(comIIIAM.ExecuteScalar());
con1.Close();
}protected void CallCIIIAF(object sender, EventArgs e)
{
OleDbCommand comIIIAF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIIA' AND Sex='F'", con1);
con1.Open();
CountCIIIAF = Convert.ToInt32(comIIIAF.ExecuteScalar());
con1.Close();
}protected void CallCIIIBM(object sender, EventArgs e)
{
OleDbCommand comIIIBM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIIB' AND Sex='M'", con1);
con1.Open();
CountCIIIBM = Convert.ToInt32(comIIIBM.ExecuteScalar());
con1.Close();
}protected void CallCIIIBF(object sender, EventArgs e)
{
OleDbCommand comIIIBF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='IIIB' AND Sex='F'", con1);
con1.Open();
CountCIIIBF = Convert.ToInt32(comIIIBF.ExecuteScalar());
con1.Close();
}protected void CallCGenM(object sender, EventArgs e)
{
OleDbCommand comGenM = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='Gen' AND Sex='M'", con1);
con1.Open();
CountCGenM = Convert.ToInt32(comGenM.ExecuteScalar());
con1.Close();
}protected void CallCGenF(object sender, EventArgs e)
{
OleDbCommand comGenF = new OleDbCommand("Select Count (Sex) From Sample2 where AdmYear='" + StrYear.SelectedValue.ToString() + "' AND Faculty='Commerce' AND Category='Gen' AND Sex='F'", con1);
con1.Open();
CountCGenF = Convert.ToInt32(comGenF.ExecuteScalar());
con1.Close();
}protected void CommerceTotal(object sender, EventArgs e)
{
CountCTotalM = CountCGenM + CountCIIIBM + CountCIIIAM + CountCIIBM + CountCIIAM + CountCCIM + CountCSCM + CountCSTM;
CountCTotalF = CountCGenF + CountCIIIBF + CountCIIIAF + CountCIIBF + CountCIIAF + CountCCIF + CountCSCF + CountCSTF;
}
/*Grand Total*/
protected void CallGrandTotal(object sender, EventArgs e)
{
TotalSC = CountASCM + CountASCF + CountSSCM + CountSSCF + CountCSCM + CountCSCF;TotalST = CountASTM + CountASTF + CountSSTM + CountSSTF + CountCSTM + CountCSTF;
TotalCI = CountACIM + CountACIF + CountSCIM + CountSCIF + CountCCIM + CountCCIF;
TotalIIA = CountAIIAM + CountAIIAF + CountSIIAM + CountSIIAF + CountCIIAM + CountCIIAF;
TotalIIB = CountAIIBM + CountAIIBF + CountSIIBM + CountSIIBF + CountCIIBM + CountCIIBF;
TotalIIIA = CountAIIIAM + CountAIIIAF + CountSIIIAM + CountSIIIAF + CountCIIIAM + CountCIIIAF;
TotalIIIB = CountAIIIBM + CountAIIIBF + CountSIIIBM + CountSIIIBF + CountCIIIBM + CountCIIIBF;
TotalGen = CountAGenM + CountAGenF + CountSGenM + CountSGenF + CountCGenM + CountCGenF;
GrandTotal1 = CountATotalM + CountATotalF + CountSTotalM + CountSTotalF + CountCTotalM + CountCTotalF;
GrandTotal2 = TotalSC + TotalST + TotalCI + TotalIIA + TotalIIB + TotalIIIA + TotalIIIB + TotalGen;
}protected void Gv1_DataBound(object sender, EventArgs e)
{
string text1 = "";
int count1 = 0;
Hashtable ht1 = new Hashtable();// loop through all rows to get row counts
foreach (GridViewRow gvr1 in Gv1.Rows)
{
if (gvr1.RowType == DataControlRowType.DataRow)
{
if (gvr1.Cells[0].Text == text1)
{
count1++;
}
else
{
if (count1 > 0)
{
ht1.Add(text1, count1);
}
text1 = gvr1.Cells[0].Text;
count1 = 1;
}
}
}if (count1 > 1)
{
ht1.Add(text1, count1);
}// loop through all rows again to set rowspan
text1 = "";
foreach (GridViewRow gvr1 in Gv1.Rows)
{
if (gvr1.RowType == DataControlRowType.DataRow)
{
if (gvr1.Cells[0].Text == text1)
{
gvr1.Cells.Remove(gvr1.Cells[0]);
}
else
{
text1 = gvr1.Cells[0].Text;
gvr1.Cells[0].RowSpan = Convert.ToInt32(ht1[text1]);
}
}
}string text2 = "";
int count2 = 0;
Hashtable ht2 = new Hashtable();// loop through all rows to get row counts
foreach (GridViewRow gvr2 in Gv1.Rows)
{
if (gvr2.RowType == DataControlRowType.DataRow)
{
if (gvr2.Cells[1].Text == text2)
{
count2++;
}
else
{
//if (count2 > 0)
//{
// ht2.Add(text2, count2);
//}
text2 = gvr2.Cells[1].Text;
count2 = 1;
}
}
}if (count2 > 1)
{
ht2.Add(text2, count2);
}// loop through all rows again to set rowspan
text2 = "";
foreach (GridViewRow gvr2 in Gv1.Rows)
{
if (gvr2.RowType == DataControlRowType.DataRow)
{
if (gvr2.Cells[1].Text == text2)
{
gvr2.Cells.Remove(gvr2.Cells[1]);
}
else
{
text2 = gvr2.Cells[1].Text;
gvr2.Cells[1].RowSpan = Convert.ToInt32(ht2[text2]);
}
}
}
}Thursday, July 14, 2016 7:18 AM -
User1724605321 posted
Hi vijaypwr61,
Please refer to below article for how to merge GridView Cells or Columns in a Row in ASP.Net using C# :
Best Regards,
Nan Yu
Monday, July 18, 2016 1:31 AM -
User-1473011517 posted
Thank You Sir...@Nan Yu
I got my problem Solved
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, July 18, 2016 9:00 AM