gridview

qq3895 2013-07-30 02:18:06
<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行,第五行性别没显示出来,这个页面时弹出页面

求解!!!!!!
...全文
113 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq3895 2013-07-30
  • 打赏
  • 举报
回复
可以了,那我的写法有错误吗?
insus 2013-07-30
  • 打赏
  • 举报
回复
蝶恋花雨 2013-07-30
  • 打赏
  • 举报
回复
第五条只有性别没有显示出来,其他都正常,只是没显示出“男”或“女” ==》检查数据库是否有数据;如有的话用下面代码试试 <%#Eval("sex").ToString()=="F"?"女":"男" %> <asp:Label ID="lbSex" runat="server" Text="<%#Eval("sex").ToString()=="F"?"女":"男" %>"></asp:Label>
蝶恋花雨 2013-07-30
  • 打赏
  • 举报
回复
<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)) { 弹出新页面 }
qq3895 2013-07-30
  • 打赏
  • 举报
回复
第五条只有性别没有显示出来,其他都正常,只是没显示出“男”或“女”
蝶恋花雨 2013-07-30
  • 打赏
  • 举报
回复
<asp:HiddenField ID="txtsex" runat="server" Value='<%# Bind("SEX") %>' /> ==》直接改成下面的多方便 三目运算 <%#Eval("sex").ToString()=="F"?"女":"男" %>
蝶恋花雨 2013-07-30
  • 打赏
  • 举报
回复
你的意思是每页显示5条数据,第5条数据性别不显示时弹出页面还是?

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧