views:

195

answers:

1
<asp:DataGrid ID="dgResetPassword" DataKeyField="user_id" OnItemCommand="resetSelect" CellPadding="10" HeaderStyle-BorderStyle="none" AutoGenerateColumns="False" runat="server" ForeColor="#333333" GridLines="None" Width="550px">
        <Columns>
            <asp:ButtonColumn DataTextField="sap_id" HeaderText="SAP ID" />
            <asp:BoundColumn DataField="lastname" HeaderText="Last Name" />
            <asp:BoundColumn DataField="firstname" HeaderText="First Name"/>
            <asp:BoundColumn DataField="username" HeaderText="User Name"/>
            <asp:BoundColumn DataField="jobtitle" HeaderText="Job Title"/>
            <asp:BoundColumn DataField="orgunit" HeaderText="Organization Unit"/>
        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditItemStyle BackColor="#999999" />
        <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
        <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" BorderStyle="None" Font-Bold="True" ForeColor="White" />
    </asp:DataGrid>

That is the grid, here is the function...

Sub resetSelect(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
    lblResponse.Text = [want to access text of username here]
    lblResponse.Visible = True
    lblID.Text = dgResetPassword.DataKeys.Item(e.Item.ItemIndex)
End Sub

How do I reference the selected items DataField text for username?

A: 

username is in the 3rd column. So you can do this (C#):

lblResponse.Text = e.Item.Cells[3].Text;
Keltex