如何在c#中使用itembounound

本文关键字:itembounound | 更新日期: 2023-09-27 18:08:27

使用c#

显示数据表格

 <asp:Panel ID="DetailsPanel" runat="server" Width="100%" Height="100%" Visible="false">
    <asp:GridView 
        ID="gridViewDetails" 
        CssClass="GridView"
        runat="server" 
        AllowPaging="True" 
        AllowSorting="true"
        AutoGenerateColumns="false" 
        DataKeyNames="employee#" 
        PageSize=25
        title=""
        Width="98%" 
        >
        <Columns>
            <asp:BoundField 
                DataField="employee#" 
                HeaderText="Employee"
                HeaderStyle-HorizontalAlign="Center" 
                ItemStyle-HorizontalAlign="Left"
                ItemStyle-Width="15%"/>
           <asp:BoundField 
                DataField="pay_start_date" 
                HeaderText="Pay&#160;Start&#160;Date"
                HeaderStyle-HorizontalAlign="Center" 
                ItemStyle-HorizontalAlign="Left"
                ItemStyle-Width="8%"/>
            <asp:BoundField 
                DataField="pay_end_date" 
                HeaderText="Pay&#160;End&#160;Date"
                HeaderStyle-HorizontalAlign="Center" 
                ItemStyle-HorizontalAlign="Left"
                ItemStyle-Width="8%"/>
            <asp:BoundField 
                DataField="income_var" 
                HeaderText="Variable&#160;Income"
                HeaderStyle-HorizontalAlign="Center" 
                ItemStyle-HorizontalAlign="Right"
                ItemStyle-Width="8%"/>
               <asp:TemplateField ItemStyle-HorizontalAlign="right" HeaderText="File Status">
                <ItemTemplate>
                    <div>
                        <a id="lnkshowhide" runat="server">
                            <asp:LinkButton ID="lnkEdit" Text="Edit" CommandName="Edit" CommandArgument='<%# Eval("employee#") %>'  runat="server"></asp:LinkButton>
                            <asp:Image ID="imgplus" runat="server" ImageUrl="~/Images/plusIcon.gif" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                    <tr id="trDesc" runat="server">
                        <td colspan="10" id="tddesc" runat="server" style="border-bottom-color: Black; border-bottom-width: 1px;">
                            <b>Response --&nbsp;</b>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:TemplateField>
       </Columns>
        <RowStyle CssClass="gridRow"/>
        <FooterStyle CssClass="gridFooter"/>
        <PagerStyle CssClass="gridPager"/>
        <SelectedRowStyle CssClass="gridSelectedRow"/>
        <EditRowStyle CssClass="gridEditRow"/>
        <AlternatingRowStyle CssClass="gridAlternativeRow"/>
    </asp:GridView>
</asp:Panel>

在c#中,我找不到ItemDataBound事件,我只能找到RowDataBound

我想使用下面的代码在ItemDataBound,如果我使用在RowDataBound得到错误在"e"

  if (e.Item.ItemType == ListItemType.Item)
  {
  }

如何在c#中使用itembounound

GridView没有ItemDataBound事件。这是DataGrid事件。它使用RowDataBound代替。RowDataBound是类似的,但您必须指定要更改的行中的哪个控件:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    Label lbl = (Label)e.Row.FindControl("ID");
        string ID = lbl.Text;
}