In the second part of this article, we have studied how to display the button in the DataGrid via the ButtonColumn. In addition, we examine how to connect the event handler with the click clicks. Below we will learn how to determine which row of DataGrid is clicked and performs the corresponding action based on this information.
Judging which one of the rows is clicked
Recall the event handler of the click button is defined as follows:
Sub EventHandlerName (Sender As Object, E AS DataGridCommandeventArgs ... End Sub
The DataGridCommandEventArgs class contains an ITEM property that contains source objects that trigger the event. The Item property is an instance of the TableRow class, which points to the line that is clicked in DataGrid. You can use the Cells property to access the columns in the tableerow class. For example, there is a DataGrid, its column information is defined as follows:
Then, in the event handler of the click button, you can get the value of a column of the clicked row by the following method:
Sub detailsClicked (sender as Object, e As DataGridCommandEventArgs) Dim buttonColumn as TableCell = e.Item.Cells (0) Dim FAQIDColumn as TableCell = e.Item.Cells (1) Dim DescColumn as TableCell = e.Item.Cells (2) Dim ButtonColtext As String = ButtonColumn.text Dim FaqidColText As String = FAQidColumn.Text Dim DescolText As String = Descolumn.Textend Sub
The example operation results are as follows:
Update the DataGrid example after the button event handler
This example shows a DataGrid web control containing the Detail button and demonstrates how to trigger a code when the button is pressed. Note You will see the information you are in the row you are clicked by clicking a Detail button.
Value of Clicked Button Column Text: Value of FAQID Column Text: 181Value of Clicked Description Column Text: How can I format numbers and date / times using ASP.NET For example, I want to format a number as a currency?.
FAQ DETAILS
FAQ ID
FAQ DESCRIPTION
144
WHERE CAN I HOST MY ASP Web Site for Free (Similar TO Geocities Or Tripod or any of the man> Free Web Site Sites)? 181
How can I Format NumBers and Date / Times Using ASP.NET? For Example, I Want To Format A Number As a Currency.
...
Source code
<% @Import namespace = "system.data"%> <% @Import namespace = "system.data.sqlclient"%>