Link to home
Start Free TrialLog in
Avatar of Angel02
Angel02

asked on

Obtain cell value using column ID in DataGrid using VB.NET

I know I did this before but can't figure it out now.

I have a datagrid with a button column. When that button is clicked, I want to obtain the values from other corrswponding columns in the same row.

 My datagrid looks like

 <asp:DataGrid ID="grdOrder" PagerStyle-CssClass="pager1" runat="server" AllowPaging="False"
                    AllowSorting="True" AutoGenerateColumns="False"
                    Visible="True">                  
                    <Columns>
                        <asp:BoundColumn DataField="Category"  HeaderText="Category"></asp:BoundColumn>
                        <asp:BoundColumn DataField="ITEM" HeaderText="Item" SortExpression="ITEM" Visible="true">
                        </asp:BoundColumn>
                       </Columns>
</asp:DataGrid>

Below if my code

Private Sub grdOrder_CellContentClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdOrder.ItemCommand

        If TypeOf e.Item Is DataGridItem Then
              Dim Category As String = e.Item.Cells(0).Text
        End If
    End Sub

Instead of using column index "0", how can I change the code to use column datafield "Category"?
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also check this

grdOrder.Columns(1).HeaderText

grdOrder.Columns(0).HeaderText