如何在c#中使用ItemDatabound

时间:2015-08-18 14:48:36

标签: c# asp.net

使用C#

的GridView

 <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中使用&#34; e&#34;

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

1 个答案:

答案 0 :(得分:1)

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

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