<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文本?
答案 0 :(得分:3)
用户名在第3列。所以你可以这样做(C#):
lblResponse.Text = e.Item.Cells[3].Text;
答案 1 :(得分:0)
这将是VB.net的做法。
lblResponse.Text = e.Item.Cells(3).Text
设置表示列及其索引的枚举可能对您有益。因此,您的代码将成为
lblResponse.Text = e.Item.Cells(DataColumns.Username).Text