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?

有帮助吗?

解决方案

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....

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top