Question

I have a FormView that has a repeater inside. In order to render the ItemTemplate I do a fake datasource and databind. Then I look for the Repeater with FindControl and do another DataSource and DataBind. So in this case HardCodedData is just a placehoder to get me to renter the FormView ItemTemplate.

FormView1.DataSource = HardCodedData;
FormView1.DataBind();

Repeater r = ((Repeater)FormView1.FindControl("repeater1"));
r.DataSource = GetMyData();
r.DataBind(); 

Is there a better way? Can I just get FormView to renter without giving it fake data? Or can I pass the repeater data through the FormView DataSource?

Was it helpful?

Solution

As a repeater control is inside the form view than you should bind this repeater control inside the form view's event DataBound threw that you will be get exact data which you want to get. Put your following code inside your FormView1_DataBound event.

Repeater r = ((Repeater)FormView1.FindControl("repeater1"));
r.DataSource = GetMyData();
r.DataBind();

May be this solution can help you....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top