Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

How to format the cell in Detail View using asp.net with c#

$
0
0

hi all,

I have a Detai View I Want to Formate his cell (##,###.00) I Achive this in Grid View . But same Code Not work with DetailView

-------.aspx page code........

<asp:DetailsView ID="DetailsView3" runat="server" Height="50px" Width="125px"
                        CssClass="bordered" Font-Size="Smaller"
                        AutoGenerateRows="False" DataSourceID="SqlDataSource3" OnRowDataBound="DetailsView3_DataBound"
                        EnableModelValidation="True">
                        <Fields>
                            <asp:BoundField DataField="ANNL" HeaderText="ANNL" SortExpression="ANNL" ItemStyle-HorizontalAlign="Right"/>
                            <asp:BoundField DataField="TECH" HeaderText="TECH" SortExpression="TECH" ItemStyle-HorizontalAlign="Right"/>
                            <asp:BoundField DataField="COMP" HeaderText="COMP" SortExpression="COMP" ItemStyle-HorizontalAlign="Right"/>
                            <asp:BoundField DataField="Total" HeaderText="Total" SortExpression="Total" ItemStyle-HorizontalAlign="Right"/>
                        </Fields>
                       
                    </asp:DetailsView>

C# -------.cs Code.....

 protected void DetailsView3_DataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;

                e.Row.Cells[1].Text = string.Format(new CultureInfo("hi-IN", true), "{0:C}", Convert.ToInt32(e.Row.Cells[1].Text.Trim())).Substring(2);
                e.Row.Cells[2].Text = string.Format(new CultureInfo("hi-IN", true), "{0:C}", Convert.ToInt32(e.Row.Cells[2].Text.Trim())).Substring(2);
                e.Row.Cells[3].Text = string.Format(new CultureInfo("hi-IN", true), "{0:C}", Convert.ToInt32(e.Row.Cells[3].Text.Trim())).Substring(2);
                e.Row.Cells[4].Text = string.Format(new CultureInfo("hi-IN", true), "{0:C}", Convert.ToInt32(e.Row.Cells[4].Text.Trim())).Substring(2);
                
            }
        }

Note : 1> No Error is showing. But o/p is not working.

2> Same code is running on gridview. o/p is correct.

3> This code is for Formating on cell for Show interger value like 1800 then show 1,800.00

Please Help me to achive Detail View also.


Viewing all articles
Browse latest Browse all 23244

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>