通过查看下面的代码,我有一个我的grIDvIEw的页脚.而问题是我的文本列[6]将不会出现,如果我使用页脚.
如果我删除页脚代码,那么我的文本列[6]出现.问题是什么?两个代码都不能使用togather?我已经设置ShowFooter =“True”
protected voID Page_Load(object sender,EventArgs e){ for (int i = 0; i < (this.GrIDVIEw1.Rows.Count); i++) { this.GrIDVIEw1.Rows[i].Cells[6].Text = "testing"; //GrIDVIEw1.Columns[1].FooterText ="footer 1"; }}
的.aspx
<asp:GrIDVIEw ID="GrIDVIEw1" runat="server" DataSourceID="sqlDataSource1" autoGenerateColumns="False" DataKeynames="ID" Cellpadding="4" Forecolor="#333333" GrIDlines="None" ShowFooter="True" onrowdatabound="GrIDVIEw1_RowDataBound"> <RowStyle Backcolor="#EFF3FB" /> <Columns> <asp:BoundFIEld datafield="reportDate" headerText="Report Date" dataformatstring="{0:dd MMMM yyyy}" SortExpression="reportDate" /> <asp:BoundFIEld datafield="sponsorBonus" headerText="Sponsor Bonus" dataformatstring="{0:0.00}" SortExpression="sponsorBonus" HTMLEncode="False" /> <asp:BoundFIEld datafield="pairingBonus" headerText="Pairing Bonus" HTMLEncode="False" SortExpression="pairingBonus" dataformatstring="{0:c}" /> <asp:BoundFIEld datafield="staticBonus" headerText="Static Bonus" SortExpression="staticBonus" /> <asp:BoundFIEld datafield="leftBonus" headerText="left Bonus" SortExpression="leftBonus" /> <asp:BoundFIEld datafield="rightBonus" headerText="Right Bonus" SortExpression="rightBonus" /> <asp:BoundFIEld headerText="Total" SortExpression="total" > <ItemStyle WIDth="100px" /> </asp:BoundFIEld> </Columns> <FooterStyle Backcolor="#507CD1" Font-Bold="True" Forecolor="White" /> <PagerStyle Backcolor="#2461BF" Forecolor="White" HorizontalAlign="Center" /> <SelectedRowStyle Backcolor="#D1DDF1" Font-Bold="True" Forecolor="#333333" /> <headerStyle Backcolor="#507CD1" Font-Bold="True" Forecolor="White" /> <EditRowStyle Backcolor="#2461BF" /> <AlternatingRowStyle Backcolor="White" /> </asp:GrIDVIEw>解决方法 示例代码:以编程方式设置页脚文本
protected voID GrIDVIEw1_RowDataBound(object sender,GrIDVIEwRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Footer) { Label lbl = (Label)e.Row.FindControl("lblTotal"); lbl.Text = GrdTotal.ToString("c"); } }
更新代码:
decimal sumFooterValue = 0; protected voID GrIDVIEw1_RowDataBound(object sender,GrIDVIEwRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DaTarow) { string sponsorBonus = ((Label)e.Row.FindControl("Label2")).Text; string pairingBonus = ((Label)e.Row.FindControl("Label3")).Text; string staticBonus = ((Label)e.Row.FindControl("Label4")).Text; string leftBonus = ((Label)e.Row.FindControl("Label5")).Text; string rightBonus = ((Label)e.Row.FindControl("Label6")).Text; decimal totalvalue = Convert.ToDecimal(sponsorBonus) + Convert.ToDecimal(pairingBonus) + Convert.ToDecimal(staticBonus) + Convert.ToDecimal(leftBonus) + Convert.ToDecimal(rightBonus); e.Row.Cells[6].Text = totalvalue.ToString(); sumFooterValue += totalvalue } if (e.Row.RowType == DataControlRowType.Footer) { Label lbl = (Label)e.Row.FindControl("lblTotal"); lbl.Text = sumFooterValue.ToString(); } }
在.aspx页面
<asp:GrIDVIEw ID="GrIDVIEw1" runat="server" DataSourceID="sqlDataSource1" autoGenerateColumns="False" DataKeynames="ID" Cellpadding="4" Forecolor="#333333" GrIDlines="None" ShowFooter="True" onrowdatabound="GrIDVIEw1_RowDataBound"> <RowStyle Backcolor="#EFF3FB" /> <Columns> <asp:TemplateFIEld headerText="Report Date" SortExpression="reportDate"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("reportDate") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("reportDate","{0:dd MMMM yyyy}") %>'></asp:Label> </ItemTemplate> </asp:TemplateFIEld> <asp:TemplateFIEld headerText="Sponsor Bonus" SortExpression="sponsorBonus"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("sponsorBonus") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("sponsorBonus","{0:0.00}") %>'></asp:Label> </ItemTemplate> </asp:TemplateFIEld> <asp:TemplateFIEld headerText="Pairing Bonus" SortExpression="pairingBonus"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("pairingBonus") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("pairingBonus","{0:c}") %>'></asp:Label> </ItemTemplate> </asp:TemplateFIEld> <asp:TemplateFIEld headerText="Static Bonus" SortExpression="staticBonus"> <EditItemTemplate> <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("staticBonus") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("staticBonus") %>'></asp:Label> </ItemTemplate> </asp:TemplateFIEld> <asp:TemplateFIEld headerText="left Bonus" SortExpression="leftBonus"> <EditItemTemplate> <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("leftBonus") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label5" runat="server" Text='<%# Bind("leftBonus") %>'></asp:Label> </ItemTemplate> </asp:TemplateFIEld> <asp:TemplateFIEld headerText="Right Bonus" SortExpression="rightBonus"> <EditItemTemplate> <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("rightBonus") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label6" runat="server" Text='<%# Bind("rightBonus") %>'></asp:Label> </ItemTemplate> </asp:TemplateFIEld> <asp:TemplateFIEld headerText="Total" SortExpression="total"> <EditItemTemplate> <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:Label ID="lbltotal" runat="server" Text="Label"></asp:Label> </FooterTemplate> <ItemTemplate> <asp:Label ID="Label7" runat="server"></asp:Label> </ItemTemplate> <ItemStyle WIDth="100px" /> </asp:TemplateFIEld> </Columns> <FooterStyle Backcolor="#507CD1" Font-Bold="True" Forecolor="White" /> <PagerStyle Backcolor="#2461BF" Forecolor="White" HorizontalAlign="Center" /> <SelectedRowStyle Backcolor="#D1DDF1" Font-Bold="True" Forecolor="#333333" /> <headerStyle Backcolor="#507CD1" Font-Bold="True" Forecolor="White" /> <EditRowStyle Backcolor="#2461BF" /> <AlternatingRowStyle Backcolor="White" /> </asp:GrIDVIEw>
我的博客 – Asp.net Gridview Article
总结以上是内存溢出为你收集整理的c# – 显示GridView的页脚总数,并在最后一列中添加列(行虎钳)全部内容,希望文章能够帮你解决c# – 显示GridView的页脚总数,并在最后一列中添加列(行虎钳)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)