?
Solved

gridview sting format string from double

Posted on 2010-01-08
6
Medium Priority
?
310 Views
Last Modified: 2013-12-17
I have field bound datatype is varchar, but stored into it is double [85.321456]
I want to display it as (85.32) . and there are some null fields.  thanks
0
Comment
Question by:fm250
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:rajvja
ID: 26208150
In the gridview rowdatabound event,

Protected Sub gvwRow_Databound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim idx As Integer = e.Row.RowIndex
            e.Row.Cells(yourcolindex).text   = formatnumber(cdbl( e.Row.Cells(yourcolindex).text),2)
    End Sub
0
 
LVL 10

Author Comment

by:fm250
ID: 26208196
Oops,  I am using C#
thanks
0
 
LVL 10

Author Comment

by:fm250
ID: 26208204
Also the field is string but contain double no.
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 11

Expert Comment

by:rajvja
ID: 26208223
Protected void gvwRow_Databound(Object sender, GridViewRowEventArgs e)
{
        If e.Row.RowType = DataControlRowType.DataRow
        {

            int idx = e.Row.RowIndex;
            e.Row.Cells(yourcolindex).text   = formatnumber(Convert.ToDouble(e.Row.Cells(yourcolindex).text),2)
        }
}
0
 
LVL 10

Author Comment

by:fm250
ID: 26208284
here is the correct format with c# but formatnumber is not known.
if (e.Row.RowType == DataControlRowType.DataRow )
{
int idx = e.Row.RowIndex;
e.Row.Cells[5].Text = formatnumber(Convert.ToDouble(e.Row.Cells[5].Text),2)
}
0
 
LVL 11

Accepted Solution

by:
rajvja earned 1000 total points
ID: 26208342
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question