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>

那是网格,这里是函数...

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

如何为用户名引用所选项目的 DataField 文本?

4

2 回答 2

3

用户名在第三列。所以你可以这样做(C#):

lblResponse.Text = e.Item.Cells[3].Text;
于 2009-04-09T14:39:35.810 回答
0

这将是 VB.net 的做法。

lblResponse.Text = e.Item.Cells(3).Text

设置一个表示列及其索引的枚举可能对您有益。因此,您的代码将成为

lblResponse.Text = e.Item.Cells(DataColumns.Username).Text
于 2015-08-28T18:36:19.860 回答