Evaluating the value of a DataGrid Item

kyory

New Member
I have a datagrid and on edit I want to check the value of one of the items in the grid and create conditional ouptut for the user. <BR><BR>How can you check the value of a particular field?<BR><BR>If MyDataGrid.Item("Article_Group") = "foo"<BR><BR> ''something<BR><BR>End if<BR><BR>Obviously I need to replace MyDataGrid.Item("Article_Group") with something that will give me the value in that field, but what???<BR><BR><BR>If you have AllowEditing = "True" on your DataGrid you can add the OnEditCommand as a DataGrid property.<BR><BR> AllowEditing = "True"<BR> OnEditCommand = "EditGrid" <BR><BR>Where EditGrid is the name of a sub you write to handle the event.<BR><BR>The EditGrid sub will have the following format:<BR><BR>Sub EditGrid(obj As Object, e As DataGridCommandEventArgs)<BR><BR>When a user clicks on the edit column of your grid, the EditGrid event will fire and you can read individual cells on the selected row as follows:<BR><BR> e.item.cells(0).text <BR><BR>Where e.item identifies the selected row and the cells(0) indicates which column you want to read.<BR><BR>ie If e.item.Cells(3).text = "Fred" then<BR><BR> do stuff......... <BR><BR> end if<BR><BR>Where Cells(3) is the fourth column in your grid.<BR><BR>If you are comparing numbers, then use Cint(e.item.Cells(3)) to convert the datagrid value to an integer. Csng (single), etc.<BR><BR>I've used this approach to read selected datagrid values and do comparisons similar to what it sounds you are doing.<BR><BR>Good Luck,<BR><BR>Tom T<BR>
 
Back
Top