<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                  BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" 
                  CellPadding="2" ForeColor="Black" GridLines="None" Width="733px" 
                  onrowdatabound="GridView1_RowDataBound" AllowPaging="True" 
                  onpageindexchanging="GridView1_PageIndexChanging" PageSize="5" 
                 >               <AlternatingRowStyle BackColor="PaleGoldenrod" />               <Columns>
               <asp:TemplateField>
                <ItemStyle HorizontalAlign="Center" />
                    <ItemTemplate>
                        <asp:CheckBox ID="chkSingle" runat="server" />
                    </ItemTemplate>
                    <HeaderTemplate>
                       选取
                    </HeaderTemplate>
               </asp:TemplateField>
                <asp:BoundField DataField="AD_EMPNO" HeaderText="工号"  
                       ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
                   </asp:BoundField>
                 <asp:BoundField DataField="CHINESE_FULLNAME" HeaderText="姓名"  
                       ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
                   </asp:BoundField>
                   <asp:TemplateField HeaderText="性别">
                       <ItemTemplate>
                         <%--  <asp:Label ID="Label2" runat="server" Text='<%# Bind("SEX") %>'></asp:Label>--%>
                          <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
                            <%--<asp:HiddenField ID="txtsex" runat="server" Value='<%# Bind("SEX") %>' />--%>
                       </ItemTemplate>
                       <EditItemTemplate>
                           <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("SEX") %>'></asp:TextBox>
                       </EditItemTemplate>
                       <ItemStyle HorizontalAlign="Center" />
                   </asp:TemplateField>
                  
                   <asp:BoundField DataField="EMAIL" HeaderText="邮件"  
                       ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
                   </asp:BoundField>
                    <asp:BoundField DataField="AGULID" HeaderText="AD"  
                       ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
                   </asp:BoundField>
                    <asp:TemplateField HeaderText="分机">
                    <ItemStyle HorizontalAlign="Center"  />
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("other.OTH_TEL") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("other.OTH_TEL") %>'></asp:TextBox>
                        </EditItemTemplate>
                   </asp:TemplateField>
                   <asp:TemplateField>
                   <ItemStyle CssClass="xx" />
                    <ItemTemplate>
                            <asp:HiddenField ID="txtsex" runat="server" Value='<%# Bind("SEX") %>' />
                    </ItemTemplate>
                   </asp:TemplateField>
               </Columns>
               <FooterStyle BackColor="Tan" />
               <HeaderStyle BackColor="Tan" Font-Bold="True" />
               <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
                   HorizontalAlign="Center" />
               <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
               <SortedAscendingCellStyle BackColor="#FAFAE7" />
               <SortedAscendingHeaderStyle BackColor="#DAC09E" />
               <SortedDescendingCellStyle BackColor="#E1DB9C" />
               <SortedDescendingHeaderStyle BackColor="#C2A47B" />
        </asp:GridView>  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
               
                HiddenField hi = (HiddenField)this.GridView1.Rows[i].Cells[7].FindControl("txtsex");
                //Response.Write(hi.Value+","+"<br />");
                Label lbl = (Label)this.GridView1.Rows[i].Cells[3].FindControl("Label2");
                if (hi.Value == "F")
                {
                    lbl.Text = "女";
                }
                else
                {
                    lbl.Text = "男";
                }
            }
        }
我绑定gridview时,用rowdatabound绑定出性别为“男”“女”,我分页每页显示5行,第五行性别没显示出来,这个页面时弹出页面求解!!!!!!GridViewlabeltextbox

解决方案 »

  1.   

      <asp:HiddenField ID="txtsex" runat="server" Value='<%# Bind("SEX") %>' />
    ==》直接改成下面的多方便 三目运算
    <%#Eval("sex").ToString()=="F"?"女":"男" %>
      

  2.   

    <asp:Label ID="lbSex" runat="server" Text="<%#Eval("sex").ToString()=="F"?"女":"男" %>"></asp:Label>
    RowDataBound事件里面 Label lbl = (Label)this.GridView1.Rows[i].Cells[3].FindControl("lbSex");if (e.Row.RowIndex == 5&&string.isnullempty(lbl.Text))
                { 
                 弹出新页面
                }
      

  3.   

    第五条只有性别没有显示出来,其他都正常,只是没显示出“男”或“女” 
    ==》检查数据库是否有数据;如有的话用下面代码试试
    <%#Eval("sex").ToString()=="F"?"女":"男" %>
    <asp:Label ID="lbSex" runat="server" Text="<%#Eval("sex").ToString()=="F"?"女":"男" %>"></asp:Label>
      

  4.   

    Refer :
    http://www.cnblogs.com/insus/articles/2055745.html