Home > DeveloperSection > Forums > Grid view event not getting triggered
Ashish Pandey

Total Post:128

Points:898
Posted on    November-27-2014 12:27 AM

 ASP.Net ASP.Net  Gridview 
Ratings:


 1 Reply(s)
 535  View(s)
Rate this:

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);

            }



Pravesh Singh

Total Post:411

Points:2881
Posted on    November-27-2014 1:51 AM

Hi Ashish, 

gvEmployee.DataSource = dtValues;

gvEmployee.RowDataBound += new GridViewRowEventHandler(gvEmployee_RowDataBound);

gvEmployee.DataBind();

gvEmployee.Width = new Unit("90%");


Don't want to miss updates? Please click the below button!

Follow MindStick