首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

gridview解决办法

2013-08-05 
gridviewasp:GridView IDGridView1 runatserver AutoGenerateColumnsFalseBackColorLightGold

gridview
<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行,第五行性别没显示出来,这个页面时弹出页面

求解!!!!!! GridView label textbox
[解决办法]
你的意思是每页显示5条数据,第5条数据性别不显示时弹出页面还是?
[解决办法]
  <asp:HiddenField ID="txtsex" runat="server" Value='<%# Bind("SEX") %>' />
==》直接改成下面的多方便 三目运算
<%#Eval("sex").ToString()=="F"?"女":"男" %>

------解决方案--------------------


<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))
            { 
             弹出新页面
            }
[解决办法]
第五条只有性别没有显示出来,其他都正常,只是没显示出“男”或“女” 
==》检查数据库是否有数据;如有的话用下面代码试试
<%#Eval("sex").ToString()=="F"?"女":"男" %>
<asp:Label ID="lbSex" runat="server" Text="<%#Eval("sex").ToString()=="F"?"女":"男" %>"></asp:Label>
[解决办法]
Refer :
http://www.cnblogs.com/insus/articles/2055745.html

热点排行