延續自藍色小舖的這個發問:http://www.blueshop.com.tw/board/FUM20041006161839...

GridView的 RowDataBound事件與 RowCreated事件裡面

      我們可以用 e.Row.RowType來判斷這一列是「表頭」「資料列(DataRow)」「表尾」或是「分頁列」

      在資料列(DataRow)裡面 ,可以透過 e.Row.RowState來判斷是否被選取?是否進入編輯模式等等

但是在ListView裡面,似乎沒有對應的作法

      因為 ItemDataBound事件裡面, e.Item.ItemType後續沒有 e.Item.ItemState


 
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)

{    // 參考資料 https://msdn.microsoft.com/zh-tw/library/system.we...     

 
if (e.Item.ItemType == ListViewItemType.DataItem)

{    // 發現 e.Item.DataItem 原來是 System.Data.DataRowView     

//Response.Write(e.Item.DataItem.ToString() + "<br>"); 
System.Data.DataRowView DRV = (System.Data.DataRowView)e.Item.DataItem;
 
// (1). 列出第一個欄位的值
Response.Write("id--" + DRV.Row.ItemArray[0] + "<br />");
 
// (2). 列出某一個欄位的值,透過.FindControl()方法
Label LB = (Label)e.Item.FindControl("nameLabel");
Response.Write(LB.Text + "<br />");
 

Response.Write(DataBinder.Eval(e.Item.DataItem, "student_id").ToString() + "<hr />"); 

}
}

推薦這篇文章,講的很清楚

在ItemDataBound取得繫結資料

http://www.dotblogs.com.tw/dyco/archive/2009/06/15...


Repeater / DataList / DataGrid  與  ListView作法不太一樣,要小心!!

後續網友的討論,可以參閱 :http://www.blueshop.com.tw/board/FUM20041006161839...


其實,參與論壇的討論

我也不知道我能否幫上忙?

但討論過程中,看到很多人的建議與解法

說真的,學到最多的還是 "我自己"

 
 

我將思想傳授他人, 他人之所得,亦無損於我之所有;

猶如一人以我的燭火點燭,光亮與他同在,我卻不因此身處黑暗。----Thomas Jefferson

......... 寫信給我,mis2000lab (at) yahoo.com.台灣 .....................................................................................

................   facebook社團   https://www.facebook.com/mis2000lab   ............................

................   Google+   https://plus.google.com/100202398389206570368/posts ..............

................  YouTube (ASP.NET) 線上教學影片  http://goo.gl/rGLocQ

arrow
arrow
    全站熱搜

    MIS2000 Lab 發表在 痞客邦 留言(0) 人氣()