FormView和ListView的行数据读取分别在什么事件中.

cs代码:
 

1).FormView:

 protected void plantForm_DataBound(object sender, EventArgs e)
    {
        FormView me = (FormView)sender;
//如果你要获取formview的数据.
// Part pt=(Part)me.DataItem;//Part是这个表的类.
        if (me.DataItem != null)
        {
            if (!CanEditByMe)
            {
                ListView contactList = (ListView)me.FindControl("contactList");
                contactList.InsertItemPosition = InsertItemPosition.None;
            }
        }
}

2). ListView:

protected void quotationList_ItemDataBound(object sender, ListViewItemEventArgs e)

    {
        ListViewDataItem item = (ListViewDataItem)e.Item;
        Quotation quotation = (Quotation)item.DataItem; //获取当前行的数据.

 

          //如果item.DataItem里的值和Quotation类里的值不是一一对应的.

          // DataBinder.GetPropertyValue(item.DataItem,"Type").ToString()   这样就可以获取某个值了.  //获取当前key.(int)me.DataKeys[e.ItemIndex].Value;


        ITextControl litUpdateOn = (ITextControl)item.FindControl("litUpdateOn");
        if (quotation.IsSubmitted)
        {
            if (quotation.UpdatedOn != null)
                litUpdateOn.Text = Convert.ToDateTime(quotation.UpdatedOn).ToString("yyyy-MM-dd");
            else
                litUpdateOn.Text = "UpdateOn is null";
        }
        else
        {
            ViewState["IsSubmitted"] = "IsSubmitted";
            litUpdateOn.Text = "Not Submitted";
        }
}

原文地址:https://www.cnblogs.com/qfb620/p/1214678.html