Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends
protected void subjectdropdown_SelectedIndexChanged(object sender, EventArgs e)
       {
           studmarkgrid.Columns.RemoveAt(0);
           comp.ACADAMICYEAR = acyeardropdown.SelectedItem.Text;
           comp.MEDIUM = mediumdropdown.SelectedItem.Text;
           string name = classdropdown.SelectedItem.Text;
           string[] divide = name.Split('-');
           comp.CLASSNAME = divide[0].ToString();
           comp.SECTIONNAME = Convert.ToChar(divide[1].Trim().ToString());
           comp.EXAMNAMES = examnamedropdown.SelectedItem.Text;
           comp.SUBJECTNAME = subjectdropdown.SelectedItem.Text;
           string examname=examnamedropdown.SelectedItem.Text;
           if (examname == "Annual Exam" || examname == "Half yearly Exam" || examname == "Quartely Exam")
           {
               DataTable getmarkfdb = inter.getmarksfromdatabaseahq(comp);
               if (getmarkfdb != null)
               {
                   if (getmarkfdb.Rows.Count > 0)
                   {
                       TemplateField adtmep = new TemplateField();
                       adtmep.ShowHeader = true;
                       adtmep.HeaderText = "InternalMark";
                       adtmep.ItemTemplate = new gridviewtemplate(DataControlRowType.DataRow, "InternalMark", "InternalMark", "TextBox");

                       studmarkgrid.Columns.Add(adtmep);
                       TemplateField extmep = new TemplateField();
                       extmep.ShowHeader = true;
                       extmep.HeaderText = "ExternalMark";
                       extmep.ItemTemplate = new gridviewtemplate(DataControlRowType.DataRow, "ExternalMark", "ExternalMark", "TextBox");

                       studmarkgrid.Columns.Add(extmep);
                       ViewState["Temptable"] = getmarkfdb;
                       studmarkgrid.DataSource = getmarkfdb;
                       studmarkgrid.DataBind();



                   }
               }


                   else
                   {
                       DataTable result = inter.getstudentlistformark(comp);
                       TemplateField inmarktemp3 = new TemplateField();
                       inmarktemp3.ShowHeader = true;
                       inmarktemp3.HeaderText = "InternalMark";
                       inmarktemp3.ItemTemplate = new gridviewtemplatewithoutbind(DataControlRowType.DataRow, "InternalMark", "InternalMark", "TextBox");

                       studmarkgrid.Columns.Add(inmarktemp3);
                       TemplateField extertemp = new TemplateField();
                       extertemp.ShowHeader = true;
                       extertemp.HeaderText = "ExternalMark";
                       extertemp.ItemTemplate = new gridviewtemplatewithoutbind(DataControlRowType.DataRow, "ExternalMark", "ExternalMark", "TextBox");
                       studmarkgrid.Columns.Add(extertemp);

                       ViewState["Temptable"] = result;
                       studmarkgrid.DataSource = result;
                       studmarkgrid.DataBind();
                       Button1.Visible = true;
                       Button2.Visible = true;


               }

           }

           else
           {
               DataTable getmarkfdb = inter.getmarksfromdatabaseothers(comp);
                      if (getmarkfdb.Rows.Count > 0)
                   {

                       TemplateField extmep = new TemplateField();
                       extmep.ShowHeader = true;
                       extmep.HeaderText = "ExternalMark";
                       extmep.ItemTemplate = new gridviewtemplate(DataControlRowType.DataRow, "ExternalMark", "ExternalMark", "TextBox");

                       studmarkgrid.Columns.Add(extmep);
                       ViewState["Temptable"] = getmarkfdb;
                       studmarkgrid.DataSource = getmarkfdb;
                       studmarkgrid.DataBind();

                   }

                   else
                   {
                       DataTable result = inter.getstudentlistformark(comp);

                       TemplateField extemp= new TemplateField();
                       extemp.ShowHeader = true;
                       extemp.HeaderText = "ExternalMark";
                       extemp.ItemTemplate = new gridviewtemplatewithoutbind(DataControlRowType.DataRow, "ExternalMark", "ExternalMark", "TextBox");
                       studmarkgrid.Columns.Add(extemp);
                       ViewState["Temptable"] = result;
                       studmarkgrid.DataSource = result;
                       studmarkgrid.DataBind();
                      // ViewState["stdmarkgrid"] = studmarkgrid;
                   }
               }
           Button1.Visible = true;
           Button2.Visible = true;


and another event handler method is
protected void Button1_Click(object sender, EventArgs e)
       {
           comp.ACADAMICYEAR = acyeardropdown.SelectedItem.Text;
           comp.MEDIUM = mediumdropdown.SelectedItem.Text;
           string clas = classdropdown.SelectedItem.Text;
           string[] cs = clas.Split('-');
           comp.CLASSNAME = cs[0].ToString();
           comp.SECTIONNAME =Convert.ToChar(cs[1].Trim().ToString());
           comp.EXAMNAMES = examnamedropdown.SelectedItem.Text;
           comp.SUBJECTID = subjectdropdown.SelectedValue.ToString();
          // System.Web.UI.WebControls.GridView grid = ViewState["stdmarkgrid"] as System.Web.UI.WebControls.GridView;

           bool studm = inter.inserstumark(comp,studmarkgrid);
           if (studm)
           {
               string msg = "Record is successfully Inserted!";
               Response.Write("<script language=JavaScript> alert('" + msg + "'); <" +
   "/script>");

           }
           else
           {
               string msg = "Record is not Inserted!";
               Response.Write("<script language=JavaScript> alert('" + msg + "'); <" +
   "/script>");
           }


       }

In first event handler i bind the gridview with datatable based on the condition. In second event hander want to send the grid value to stored in database. but i cannot read the value from gridview in inserstumark method. by default i set the gridview viewstate for enabled. but still i could not get value.
Posted
Updated 3-Oct-13 2:26am
v2
Comments
ZurdoDev 3-Oct-13 13:59pm    
That's a lot of code. Don't expect anyone to read all the way through. Please be clear as to which lines you are specifically referencing.
baskaran chellasamy 3-Oct-13 14:04pm    
In bool studm = inter.inserstumark(comp,studmarkgrid) i send the gridview to read data from gridview and stored to database. but this method is in the "button1_click" event. and i bind the gridview in the "subjectdropdown_SelectedIndexChanged". so in "inserstumark" i got the null value for all data that bind in the gridview
ZurdoDev 3-Oct-13 14:06pm    
Perhaps you need to show the inserstumark method.
baskaran chellasamy 3-Oct-13 14:10pm    
This is my Insertumark method.
public bool inserstumark(Commonpropertis comp, System.Web.UI.WebControls.GridView grid)
{
bool result = false;
if (comp.EXAMNAMES != "Annual Exam" || comp.EXAMNAMES!="Half yearly Exam"|| comp.EXAMNAMES!="Quartely Exam" )
{

int rows = grid.Rows.Count;
for (int i = 0; i < rows; i++)
{
comp.ROLLNUMBER = (grid.Rows[i].Cells[1].Text);
// comp.ADMISSIONNUMBER = Convert.ToInt32(grid.Rows[i].Cells[0].Text);
// System.Web.UI.WebControls.Label lbl = grid.Rows[i].FindControl("lblrollno") as System.Web.UI.WebControls.Label;
// comp.ROLLNUMBER = lbl.Text;
// comp.NAME = grid.Rows[i].Cells[2].Text;
System.Web.UI.WebControls.TextBox txt = grid.Rows[i].FindControl("mark2txt") as System.Web.UI.WebControls.TextBox;
comp.EXTERNALMARK =Convert.ToInt32(txt.Text);
result= userdao.inserstumark1(comp);
}
return result;
baskaran chellasamy 3-Oct-13 14:31pm    
anything friend.

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