Evaluating the value of a DataGrid Item

Results 1 to 2 of 2

Thread: Evaluating the value of a DataGrid Item

  1. #1
    Join Date
    Dec 1969

    Default Evaluating the value of a DataGrid Item

    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> &#039;&#039;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>

  2. #2
    Join Date
    Dec 1969

    Default RE: Evaluating the value of a DataGrid Item

    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&#039;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>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts