不明确的EventArgs

时间:2015-09-11 15:20:25

标签: c# asp.net webforms

在搜索SO并从Microsoft SDN档案中阅读有关EventArgs类之后,我不确定下面的代码如何获取其数据。

我知道EventArgs只是一个包含数据的参数,但我没有得到 它有数据的方式。通过OnItemDataBound在前面调用下面的方法,这是有道理的。

我搜索了后面的代码,但ID="rptSectionDates"没有数据绑定,所以我不确定这是如何工作的。

问题:有人可以告诉我后面代码中的e.Item.DataItem有哪些数据?

编辑:扩展前端以获得进一步的帮助。

<asp:Repeater ID="rptSections" runat="server" EnableViewState="false" OnItemDataBound="rptSections_ItemDataBound">
<ItemTemplate>
    <div class="section-information-wrapper">
        <div class="section-information-header">
            <div class="section-information-header-left">
                <h3>
                    <span class="section-information-crn-head"><a title="<%# GlobalHelper.GetSetting("Course.CRNToolTip") %>">CRN</a>: </span>
                    <span class="section-information-crn-number"><%# Eval("CRN") %></span>
                </h3>
            </div>
            <div class="section-information-header-right"></div>
        </div>
        <div class="section-information-body">
            <table>
                <thead>
                    <tr class="section-information-subheader">
                        <th class="section-information-date"><h4>Date(s)</h4></th>
                        <asp:PlaceHolder ID="phNonDistanceColumnHeaders" runat="server">
                            <th class="section-information-day"><h4>Day(s)</h4></th>
                            <th class="section-information-time"><h4>Time</h4></th>
                            <th class="section-information-building"><h4>Building</h4></th>
                            <th class="section-information-room"><h4>Room</h4></th>
                        </asp:PlaceHolder>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="rptSectionDates" runat="server" OnItemDataBound="rptSectionDates_ItemDataBound">
                        <ItemTemplate>
                            <asp:PlaceHolder ID="phAnd" runat="server" Visible="false">
                                <tr class="section-information-and">
                                    <td colspan="5">
                                        <b>and</b>
                                    </td>
                                </tr>
                            </asp:PlaceHolder>
                            <tr class="section-information-content">
                                <td><asp:Literal ID="litDates" runat="server" /></td>
                                <asp:PlaceHolder ID="phNonDistanceColumns" runat="server">
                                    <td><asp:Literal ID="litDaysOfWeek" runat="server" /></td>
                                    <td><asp:Literal ID="litTimes" runat="server" /></td>
                                    <td><asp:HyperLink ID="hypBuilding" runat="server" Enabled="false" /></td>
                                    <td><asp:HyperLink ID="hypRoom" runat="server" Enabled="false" /></td>
                                </asp:PlaceHolder>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
            </table>
            <div class="section-information-additional-wrapper clearfix">                                                     
                <div class="section-information-additional-left">
                    <table>
                        <tbody>                  
                            <tr class="section-information-additional">
                                <td class="section-infomation-additional-subheader"><asp:PlaceHolder ID="phTeacher" runat="server" Visible="false"><h4>Teacher: </h4></asp:PlaceHolder></td>
                                <td class="section-infomation-additional-content"><asp:HyperLink ID="hypTeacher" runat="server" Visible="false" /><asp:Literal ID="litTeacher" runat="server" Visible="false" /></td>
                            </tr>
                            <tr class="section-information-additional">
                                <td class="section-infomation-additional-subheader"><h4>Hours: </h4></td>
                                <td class="section-infomation-additional-content"><%=m_Course.CourseHours.ToString("0.##") %></td>
                            </tr>
                            <tr class="section-information-additional">
                                <td class="section-infomation-additional-subheader"><h4>Fee: </h4></td>
                                <td class="section-infomation-additional-content"><asp:Literal ID="litFee" runat="server" /> <asp:Literal ID="litFeeNote" runat="server" /></td>
                            </tr>
                            <tr id="trSectionNotes" runat="server" visible="false" class="section-information-additional">
                                <td class="section-infomation-additional-subheader"><h4>Note: </h4></td>
                                <td class="section-infomation-additional-content"><%# Eval("SectionNotes") %></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="section-information-additional-right clearfix">
                    <div class="section-icon-wrapper">
                        <span class="blue-button"><asp:Literal ID="litRegistrationLink" runat="server" /></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</ItemTemplate>

返回:

protected void rptSectionDates_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        CourseSection section = (CourseSection)e.Item.DataItem;

        if (e.Item.ItemIndex > 0)
        {
            PlaceHolder phAnd = (PlaceHolder)e.Item.FindControl("phAnd");
            phAnd.Visible = true;
        }

        Literal litDates = (Literal)e.Item.FindControl("litDates");

        if (section.StartDate.Date.Equals(section.EndDate.Date))
        {
            litDates.Text = section.StartDate.ToString(DATE_FORMAT);
        }
        else
        {
            litDates.Text = string.Concat(
                section.StartDate.ToString(DATE_FORMAT),
                " &#8211; ", 
                section.EndDate.ToString(DATE_FORMAT));
        }

        ...
}

0 个答案:

没有答案