Click here to Skip to main content
16,008,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends

This is my row created event code
protected void classmarkgrid_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                string examname = examdropdown.SelectedItem.Text;
                if (examname == "AdmissionNumber" || examname == "Rollnumber" || examname == "Name")
                {

                    CustomizeGridHeader1((GridView)sender, e.Row, 2);
                }
                else
                {
                    CustomizeGridHeader((GridView)sender, e.Row, 2);
                }
            }
        }

private void CustomizeGridHeader(GridView timeSheetGrid, GridViewRow gridRow, int headerLevels)
        {
            for (int item = 1; item <= headerLevels; item++)
            {
                //creating new header row
                GridViewRow gridviewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

                IEnumerable<IGrouping<string, string>> gridHeaders = null;

                //reading existing header 
                gridHeaders = gridRow.Cells.Cast<TableCell>()
                            .Select(cell => GetHeaderText(cell.Text, item))
                            .GroupBy(headerText => headerText);

                foreach (var header in gridHeaders)
                {
                    TableHeaderCell cell = new TableHeaderCell();

                    if (item == 2)
                    {
                        if (header.Key == "AdmissionNumber" || header.Key == "Rollnumber" || header.Key == "Name")
                        {
                            cell.Text = "";
                        }
                        else
                        {
                            cell.Text = header.Key.Substring(header.Key.LastIndexOf(_seperator) + 1);
                        }
                    }
                    else
                    {
                        cell.Text = header.Key.ToString();
                        if (!((cell.Text.Contains("AdmissionNumber")) || (cell.Text.Contains("Rollnumber")) || (cell.Text.Contains("Name"))))
                        {
                            cell.ColumnSpan = 1;
                        }
                    }
                    gridviewRow.Cells.Add(cell);
                }
                // Adding new header to the grid
                timeSheetGrid.Controls[0].Controls.AddAt(gridRow.RowIndex, gridviewRow);
            }
            //hiding existing header
            gridRow.Visible = false;
        }


In this event I bind the data to gridview with splited column. after that i want to read the data from gridview for saving data to database in save button click event. but before fire button event, once again row created event is fired. so my gridview has lose the inserted the data before going to save. how can solve the problem. I am binding the gridview before call the save button event fire
Posted

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