2009-04-09 29 views
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> 

这就是网格,这里是功能...如何访问DataGrid的选定BoundColumn的文本?

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 

我如何引用选定的项目数据字段文本的用户名?

回答

3

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

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

这将是VB.net的方式。

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

建立一个代表列及其索引的枚举可能是有益的。因此,您的代码可能会变成

lblResponse.Text = e.Item.Cells(DataColumns.Username).Text 
相关问题