在本文第二部分我們研究了如何通過ButtonColumn標記在DataGrid中顯示按鈕
判斷哪一行的按鈕被點擊
回想一下點擊按鈕的事件處理程序定義如下
Sub eventHandlerName(sender as Object
End Sub
DataGridCommandEventArgs類包含一個Item屬性
<asp:DataGrid runat=
<Columns>
<asp:ButtonColumn Text=
<asp:BoundColumn DataField=
<asp:BoundColumn DataField=
</Columns>
</asp:datagrid>
那麼在點擊按鈕的事件處理程序中
Sub detailsClicked(sender as Object
Dim buttonColumn as TableCell = e
Dim FAQIDColumn as TableCell = e
Dim DescColumn as TableCell = e
Dim buttonColText as String = buttonColumn
Dim FAQIDColText as String = FAQIDColumn
Dim DescColText as String = DescColumn
End Sub
示例運行結果如下:
更新按鈕事件處理程序後的DataGrid示例
本示例展示了一個包含Detail按鈕的DataGrid Web控件並演示了當按下按鈕時如何觸發一段代碼
Value of Clicked Button Column Text:
Value of FAQID Column Text:
Value of Clicked Description Column Text: How can I format numbers and date/times using ASP
FAQ Details
FAQ ID
FAQ Description
Where can I host my ASP Web site for free (similar to GeoCities or Tripod or any of the many other free Web site sites)?
How can I format numbers and date/times using ASP
…
源代碼
<% @Import Namespace=
<% @Import Namespace=
<script language=
Sub Page_Load(sender as Object
If Not Page
BindData()
End If
End Sub
Sub BindData()
Dim myConnection as New SqlConnection(ConfigurationSettings
Const strSQL as String =
Dim myCommand as New SqlCommand(strSQL
myConnection
dgPopularFAQs
dgPopularFAQs
End Sub
Sub dispDetails(sender as Object
Dim buttonColumn as TableCell = e
Dim FAQIDColumn as TableCell = e
Dim DescColumn as TableCell = e
Dim buttonColText as String = buttonColumn
Dim FAQIDColText as String = FAQIDColumn
Dim DescColText as String = DescColumn
lblBCT
lblFCT
lblDCT
End Sub
</script>
<form runat=
<b>Value of Clicked Button Column Text</b>:
<asp:label id=
<b>Value of FAQID Column Text</b>:
<asp:label id=
<b>Value of Clicked Description Column Text</b>:
<asp:label id=
<asp:DataGrid runat=
BackColor=
HorizontalAlign=
Font
Font
OnItemCommand=
<HeaderStyle BackColor=
<AlternatingItemStyle BackColor=
<Columns>
<asp:ButtonColumn Text=
<asp:BoundColumn DataField=
<asp:BoundColumn DataField=
</Columns>
</asp:datagrid>
</form>
請仔細檢查上面的示例
在本文開始部分我講述了一個電子商務公司的場景
雖然我們不希望在DataGrid中顯示FAQID列
因此我們所要做的就是改寫detailsClicked事件處理程序
<script language=
Sub Page_Load(sender as Object
If Not Page
BindData()
End If
End Sub
Sub BindData()
End Sub
Sub detailsClicked(sender as Object
End Sub
</script>
<form runat=
<asp:DataGrid runat=
</asp:datagrid>
<asp:DataGrid runat=
<Columns>
<asp:ButtonColumn Text=
ButtonType=
<asp:BoundColumn DataField=
<asp:BoundColumn DataField=
</Columns>
</asp:datagrid>
</form>
示例運行結果如下:
本示例展示了如何在DataGrid的每一行中顯示概要信息和一個Detail按鈕
Category Name
FAQ Description
Views
Author
Author
Date Added
Getting Started
Where can I host my ASP Web site for free (similar to GeoCities or Tripod or any of the many other free Web site sites)?
Scott Mitchell
mitchel
FAQ Details
FAQ Description
From:http://tw.wingwit.com/Article/program/net/201311/11785.html