Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dynamic grid View with template fields and bound fields as columns

for the first page load all binding looks fine.values are populated in all columns

when I trigger an event such as selected index changed in Drop downlist present in the column header(inside template field ) the binding are lost and the event is never catched.

how to retain controls when post back occurs and how to resolve this problem ?
this is my code

C#
private void Subjectbind(string ExamYear, string ExamType)
{
 
if (ddlExamYear.SelectedIndex == 0)
ExamYear = ddlExamYear.SelectedValue;
if (ddlExamType.SelectedIndex == 0)
ExamType = ddlExamType.SelectedValue;
 


 
List lstCourses =
objMDLClass.GetAllExamTypeCourses(Convert.ToInt32(ExamType),
ExamYear);
objManage = new StudentManage((Users)Session["user"]);
 

foreach (SpGetExamTypeCourses_Result objCourse in lstCourses)
{
 
GridTemplateColumn col = new GridTemplateColumn();
col.UniqueName = objCourse.CourseId.ToString();
col.HeaderText = objCourse.CourseName;
col.ItemTemplate = new GridCustomItemTemplate(objManage.GetExamAnalysisReport(
Convert.ToInt32(objCourse.CourseId), Convert.ToInt32(ExamType),
ExamYear));
 

 
gvSubwisePerformance.MasterTableView.Columns.Add(col);
 
}
gvSubwisePerformance.Rebind();
}
Posted
Updated 27-Dec-14 0:53am
v3

1 solution

Bind the gridview on Page_Load only if it is not a postback.
Check this out: gridview loses dynamically created template column when paging[^]
 
Share this answer
 

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