从e.Row.DataItem分配数据

时间:2014-12-10 09:35:30

标签: asp.net

由于我是asp的新手,我在基于e.Row.DataItem进行分配时遇到了一个小问题。 代码:

protected void grdStaffReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
    ApplicationRegistration appReg = new ApplicationRegistration();

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        All_Ticket allTicket = e.Row.DataItem as All_Ticket;
        if (allTicket != null)
        {
            Label lblTicketId = ((Label)e.Row.FindControl("lblTicketId"));
            lblTicketId.Text = "PHDT" + allTicket.TicketId;
            Label lblStartedBy = ((Label)e.Row.FindControl("lblStartedBy"));
            lblStartedBy.Text = this.GetTicketStartBy(allTicket.ClientId);
            HyperLink hylnk = (HyperLink)e.Row.FindControl("HyperLink1");
            hylnk.NavigateUrl = "~/User/DisplayTicket.aspx?TicketId=" + allTicket.TicketId + " &AppId=" + allTicket.AppId;
            Label lblIsCloesed = ((Label)e.Row.FindControl("lblIsCloesed"));
            if (allTicket.isClosed == true)
            {
                hylnk.ForeColor = System.Drawing.Color.Green;
                lblIsCloesed.Text = "Yes";
            }
            else
            {
                lblIsCloesed.Text = "No";
                hylnk.ForeColor = System.Drawing.Color.Blue;
            }
            Label lblLastUpdateBy = ((Label)e.Row.FindControl("lblLastUpdateBy"));
            lblLastUpdateBy.Text = this.GetTicketLastUpdateBy(allTicket.TicketId, lblStartedBy.Text);
            TicketRegistration ticReg = new TicketRegistration();
            Ticket_Reply tic = ticReg.GetMaxTicketByTicketId(allTicket.TicketId);
            Label lblUpdationDt = (Label)e.Row.FindControl("lblUpdationDt");
            Label lblclient = (Label)e.Row.FindControl("lblClint");
            var user = userManage.GetClientUserByUserId(allTicket.ClientId);
            lblclient.Text = _clientReg.GetClientNameByID(user.ParentId);
            if (tic != null)
            {
                lblUpdationDt.Text = Convert.ToString(tic.CreationDt);
            }
            else
            {
                lblUpdationDt.Text = Convert.ToString(allTicket.CreationDt);
            }

            Label lblAppId = ((Label)e.Row.FindControl("lblApplicaton"));
            lblAppId.Text = appReg.GetAppNameByID(allTicket.AppId);

            Label lblSNo = ((Label)e.Row.FindControl("lblSno"));
            lblSNo.Text = (++i).ToString();
        }
    }
}

注意:这里e.Row.DataItem有数据(通过放置断点看到),但是当执行此操作时,allTicket没有分配任何数据。

请恢复解决方案

0 个答案:

没有答案