所有这些都发生在同一个用户控件中,因此不应该有所作为。
<asp:Repeater ID="rptActivity" runat="server" OnItemCreated="rptActivity_ItemCreated">
<ItemTemplate>
<div class="under-label">
<div class="activity">
<%#Eval("ActivityName")%>
<input type="hidden" name="activityId" value='<%#Eval("ActivityId")%>' />
</div>
<div class="status">
<asp:DropDownList ID="ddlStatuses" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id" runat="server"></asp:DropDownList>
</div>
<div class="comment">
<textarea name="comments" cols="35" rows="3" name="comment" style="float: left; margin: 0px 0px 0px 25px; font-family: Geneva, Arial, Helvetica, sans-serif;"><%#Eval("Comment")%></textarea>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
我在转发器的 itemcreated 事件中有以下代码:
protected void rptActivity_ItemCreated(object sender, RepeaterItemEventArgs e)
{
var helper = (UpdateActivitiesHelper)e.Item.DataItem;
DropDownList ddl = (DropDownList)FindControl("ddlStatuses");
ddl.SelectedValue = helper.StatusId.ToString();
}
当我尝试使用 ddl 时,它会抛出NullReferenceException
.
有任何想法吗?