绑定数据时gridview中的%问题 [英] % issue in gridview when i bind the data

查看:41
本文介绍了绑定数据时gridview中的%问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据绑定到网格视图。但是第9列我添加了%符号。但问题是在网格视图中假设数据像0.00089那样的值被转换为0.0我正在使用此.aspx代码





i Bind the data into Grid view.but 9th column i added % Symbol.but problem is in grid view suppose data like 0.00089 that's value is converted to 0.0 i am using this .aspx code


<asp:GridView ID="grvMergeHeader" runat="server" CssClass="HeaderStyle"

                           OnRowCreated="grvMergeHeader_RowCreated1" Width="100%"

                           OnRowDataBound="grvMergeHeader_RowDataBound" AllowSorting="True"

                           PageSize="25" AutoGenerateColumns="false"

           ForeColor="White" Font-Names="Arial"  GridLines="None" >
                           <HeaderStyle Font-Bold="False" BorderWidth="0"  />
                           <AlternatingRowStyle BackColor="White"  Font-Bold="false"   />
                         <Columns>
                               <asp:BoundField DataField="State" HeaderText="State"  ItemStyle-Width="5%" ItemStyle-HorizontalAlign="Left" ItemStyle-Height="3px" HeaderStyle-CssClass="ff1" />
                               <asp:BoundField DataField="LOB" HeaderText="LOB"  ItemStyle-Width="15%" ItemStyle-HorizontalAlign="Left" ItemStyle-Height="3px" HeaderStyle-CssClass="ff2" />
                               <asp:BoundField DataField="DPW" HeaderText="2012 DPW"  ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" DataFormatString="{0:0.00}" />
                               <asp:BoundField DataField="10Y_PremiumGrowth" HeaderText="Premium growth"  ItemStyle-Width="8%"   ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" DataFormatString="{0:0.00}" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="Prem_growth" />
                               <asp:BoundField DataField="10Y_OutperformUnderperform" HeaderText="Loss&LAE Incurred Out(Under) performance "  ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px"  HeaderStyle-CssClass="LossLAE10" />
                               <asp:BoundField DataField="5Y_PremiumGrowth" HeaderText=" premium growth " ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right"  ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="Prem_growth"  />
                               <asp:BoundField DataField="5Y_OutperformUnderperform" HeaderText=" Loss&LAE Incurred Out(Under) performance" ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="LossLAE5"/>
                               <asp:BoundField DataField="3Y_PremiumGrowth" HeaderText="premium growth " ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right"  ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="Prem_growth" />
                               <asp:BoundField DataField="3Y_OutperformUnderperform" HeaderText="Loss&LAE Incurred Out(Under) performance" ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right"  ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="LossLAE3"/>
                               <asp:BoundField DataField="10Y_LossLAERatio" HeaderText="10years" ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="yrs1035"  />
                               <asp:BoundField DataField="5Y_LossLAERatio" HeaderText="5 years " ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px"  HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="yrs1035"/>
                               <asp:BoundField DataField="3Y_LossLAERatio" HeaderText="3 years " ItemStyle-Width="8%"   ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="yrs1035"/>
                           </Columns>

                            <RowStyle BackColor="#c9c9c7"  Font-Size="8" Font-Names="Arial" ForeColor="Black" />
                            </asp:GridView>





我正在使用.cs代码





and i am using .cs code

protected void grvMergeHeader_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false; // Invisibiling Year Header Cell
                e.Row.Cells[1].Visible = false; // Invisibiling Period Header Cell
                e.Row.Cells[2].Visible = false; // Invisibiling Audited By Header Cell
            }


            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drview = e.Row.DataItem as DataRowView;


                foreach (TableCell cell in e.Row.Cells)
                {
                    decimal number;
                    if (Decimal.TryParse(cell.Text, out number))
                    {
                        decimal val = Convert.ToDecimal(number);

                        string finalValue = string.Empty;

                        string[] combinedValue = val.ToString().Split('.');

                        if (combinedValue.Length > 1)
                        {
                            if (combinedValue[1].Length > 1)
                            {
                                finalValue = combinedValue[0] + "." + combinedValue[1].Substring(0, 2);

                            }
                            else
                            {
                                finalValue = combinedValue[0] + "." + combinedValue[1].Substring(0, 2);

                            }

                        }
                        else
                        {
                            finalValue = combinedValue[0];
                        }

                        if (Convert.ToDecimal(finalValue) < 0)
                        {
                            finalValue = finalValue.ToString().Replace("-", "");
                            finalValue = "(" + finalValue + ")";

                        }
                        else
                            if (Convert.ToDecimal(finalValue) == 0)
                            {
                                finalValue = "_";

                            }


                        cell.Text = finalValue;
                    }

                }


                if (drview.Row[9] == DBNull.Value)
                {

                    e.Row.Cells[9].Text = e.Row.Cells[9].Text;

                }
                else if (drview.Row[9] != DBNull.Value)
                {
                    double value = Convert.ToDouble(drview.Row[9]);
                    if (value == 0)
                    {
                        e.Row.Cells[9].Text = e.Row.Cells[9].Text;
                    }
                    else
                    {
                        e.Row.Cells[9].Text = e.Row.Cells[9].Text + "%";
                    }
                }



in my page if value is 0 it’s replaced to ’_’,if value is -ve value is converted to (1.78) like this My issue is If value is 0 it’s replaced _ it’s ok some times 0.00089 value is converted to ’0’ when i bind _ symbol it’s takes original value and bind _% like this





if you have any idea please share to me


in my page if value is 0 it's replaced to '_',if value is -ve value is converted to (1.78) like this My issue is If value is 0 it's replaced _ it's ok some times 0.00089 value is converted to '0' when i bind _ symbol it's takes original value and bind _% like this


if you have any idea please share to me

推荐答案

Use the asccii code instead of ’%’, I believe it is \u0037
Use the asccii code instead of '%', I believe it is \u0037


这篇关于绑定数据时gridview中的%问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆