Grid view event not getting triggered

I have a gridview created dynamically , now i am trying to do edit each column by keeping a link button. But the rowdatabound event is not getting triggered.Where i might have gone wrong? Below is my code :

 

dtValues = gObj.GetAllDocumentsHistoryList();
            dtHeader = gObj.GetAllHeaderList();
            GridView gvEmployee = new GridView();
            gvEmployee.ShowHeaderWhenEmpty = true;
            gvEmployee.EmptyDataText = "Sorry No History Records Found !!!!!!!";
            gvEmployee.AutoGenerateColumns = false;
            for (int i = 0; i < dtValues.Columns.Count; i++)
            {
                string name = dtValues.Columns[i].ColumnName.ToString();
                BoundField boundfield = new BoundField();
                boundfield.DataField = dtValues.Columns[i].ColumnName.ToString();
 
                for (int j = 0; j < dtHeader.Rows.Count; j++)
                {
                    if (dtHeader.Rows[j]["ColCode"].ToString() == dtValues.Columns[i].ColumnName.ToString())
                    {
                        boundfield.HeaderText = dtHeader.Rows[j]["ColName"].ToString();
                        if (boundfield.HeaderText.Contains("Date") || boundfield.HeaderText.Contains("DocExpiry"))
                        {
                            boundfield.DataFormatString = "{0:dd/MMM/yyyy}";
                        }
                    }
                    else if (dtValues.Columns[i].ColumnName.ToString() == "Last Modified Date")
                    {
                        boundfield.HeaderText = "Last Modified Date";
                        boundfield.DataFormatString = "{0:dd/MMM/yyyy}";
                    }
                }
                gvEmployee.Columns.Add(boundfield);
            }

Last updated:11/27/2014 1:51:31 AM

1 Answers

Pravesh Singh
Pravesh Singh

Hi Ashish, 

gvEmployee.DataSource = dtValues;
gvEmployee.RowDataBound += new GridViewRowEventHandler(gvEmployee_RowDataBound);
gvEmployee.DataBind();
gvEmployee.Width = new Unit('90%');

Answer