Click here to Skip to main content
14,920,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
C#
protected void submitbtn_Click(object sender, EventArgs e)
        {
            classmarkgrid.Columns.Clear();
            comp.ACADAMICYEAR = acyeardropdown.SelectedItem.Text.ToString();
            comp.MEDIUM = mediumdropdown.SelectedItem.Text.ToString();
            string cname = classdropdown.SelectedItem.Text;
            string[] divide = cname.Split('-');
            comp.CLASSNAME = divide[0].ToString();
            comp.SECTIONNAME = Convert.ToChar(divide[1].Trim().ToString());
            comp.EXAMNAMES = examdropdown.SelectedItem.Text;
            DataSet getmark = inter.getclassmark(comp);
            if (getmark.Tables.Count >0)
            {
                if (comp.EXAMNAMES == "Quartely Exam" || comp.EXAMNAMES == "Half yearly exam" || comp.EXAMNAMES == "Annual Exam")
                {
                    DataTable bindtable = inter.bindtablesformarksingrid(getmark);
                    classmarkgrid.DataSource = bindtable;
                }
                else
                {
                    DataTable bindtable1 = inter.bindtablesformarkextergrid(getmark);
                    classmarkgrid.DataSource = bindtable1;
                    
                }
                 
                classmarkgrid.DataBind(); //problem in this databind method. Here row databound event is not fired.

            }
            else
            {
                DataTable studentlist = inter.getstudentlistformark(comp);
                
                DataTable getsubjectforclass = inter.getsubjectlist(comp);

                DataTable gridback =mark.setgrid(studentlist, getsubjectforclass, comp);
                if (comp.EXAMNAMES == "Quartely Exam" || comp.EXAMNAMES == "Half yearly exam" || comp.EXAMNAMES == "Annual Exam")
                {

                    for (int i = 0; i < gridback.Columns.Count; i++)
                    {
                        
                        if (i >= 3)
                        {
                            TemplateField adtmep = new TemplateField();
                            adtmep.ShowHeader = true;
                            adtmep.HeaderText = gridback.Columns[i].ColumnName;
                            adtmep.ItemTemplate = new  gridviewtemplatewithoutbind(DataControlRowType.DataRow, gridback.Columns[i].ColumnName, gridback.Columns[i].ColumnName, "TextBox");
                            classmarkgrid.Columns.Add(adtmep);
                            continue;
                        }
                        TemplateField adtmep1 = new TemplateField();
                        adtmep1.ShowHeader = true;
                        adtmep1.HeaderText = gridback.Columns[i].ColumnName;
                        adtmep1.ItemTemplate = new gridviewtemplate(DataControlRowType.DataRow, gridback.Columns[i].ColumnName, gridback.Columns[i].ColumnName, "Label");
                        classmarkgrid.Columns.Add(adtmep1);


                        
                    }
                }
                else
                {
                    for (int i = 0; i < gridback.Columns.Count; i++)
                    {

                        if (i >= 3)
                        {
                            TemplateField adtmep = new TemplateField();
                            adtmep.ShowHeader = true;
                            adtmep.HeaderText = gridback.Columns[i].ColumnName;
                            adtmep.ItemTemplate = new gridviewtemplatewithoutbind(DataControlRowType.DataRow, gridback.Columns[i].ColumnName, gridback.Columns[i].ColumnName, "TextBox");
                            classmarkgrid.Columns.Add(adtmep);
                            continue;
                        }
                        
                        TemplateField adtmep1 = new TemplateField();
                        adtmep1.ShowHeader = true;
                        adtmep1.HeaderText = gridback.Columns[i].ColumnName;
                        adtmep1.ItemTemplate = new gridviewtemplate(DataControlRowType.DataRow, gridback.Columns[i].ColumnName, gridback.Columns[i].ColumnName, "Label");
                        classmarkgrid.Columns.Add(adtmep1);



                    }
                }
                

                classmarkgrid.DataSource = gridback;
                classmarkgrid.DataBind();// here it is fired
              //  ViewState["bindclassmark"] = gridback;
                
                Savebtn.Visible = true;
                Cancelbtn.Visible = true;
            }
            

        }

In this code classgridview rowdatabound event fires for the 'else' condition. its ok. but for' if' condition rowdatabound event not fired.
Posted
Updated 19-Oct-13 6:06am
v4

1 solution

The only way you can make the grid's on data row bound event to be fired is by registering the onrowdatabound event of your grid.

Try doing something like in this example.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900