Can child controls use their parent data source?
I have the following allowance:
<div class="section"> <p runat="server" id="sectionName"></p> </div> <div class="label"> <div class="activity-header">Activity</div> <div class="status-header">Status</div> <div class="comment-header">Comment</div> </div> <asp:Repeater ID="rptActivity" runat="server"> <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" DataValueField="Id" DataTextField="Name" DataSourceID="SqlDataSource1" 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> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PhumafConnectionString %>" SelectCommand="SELECT * FROM [Status]"> </asp:SqlDataSource> The data source for rptActivity Repeater is List and Helper, as shown below:
public class Helper { public string ActivityName { get; set; } public long ActivityId { get; set; } public long StatusId { get; set; } public string Comment { get; set; } } As you can see, I bind the appropriate fields to the properties of the object and bind all ddlStatuses to the data source, which returns all the statuses. However, since this is an update screen, I want to have the previously selected status selected, and I have this identifier through the prop StatusId of the helper object.
I tried setting SelectedValue from ddlStatuses to <%# Eval("StatusId") %> , but he excluded that I can only call the details from the data source to which the control is bound.
Mostly I have StatusIds, I have to make them selected in ddlStatuses.
How can i do this?
EDIT:
I forgot to mention that one of the solutions that I had in mind includes List<Status> as a property in the helper class, so that I will have the status ID as well as all other statuses, however this will not work if I cannot use the parent source data.
I would use the ItemCreated event http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcreated.aspx