Solved

ASP.net DataGrid -- convert string to Int

Posted on 2011-03-09
3
453 Views
Last Modified: 2012-05-11
Hi,

i have a working DataGrid1 whose source is XML file.

lately, i realized that i could not able to use DateFormatString as the values returned from XML are all strings. (pls correct me if wrong)....below code doesn't apply any format
<asp:BoundField HeaderText="Start QTY" DataField="start_qty" DataFormatString="{0:N3}" ApplyFormatInEditMode="True" HtmlEncode="False"/>

can you pls suggest me how to convert from string to int or decimal

------- DataGrid -------
 rowDataSet.ReadXml(filepath);
            pnlGrid.DataSource = rowDataSet.Tables[0].DefaultView;
            pnlGrid.DataBind();
--------------------------------

 <asp:GridView ID="pnlGrid" runat="server" CellPadding="4" AutoGenerateColumns="False"                    EnableModelValidation="True" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <Columns>
                             <asp:BoundField HeaderText="Symbol" DataField="symbol" />
                          <asp:BoundField HeaderText="Start QTY" DataField="start_qty" DataFormatString="{0:N3}" ApplyFormatInEditMode="True" HtmlEncode="False"/>
                            <asp:BoundField HeaderText="End QTY" DataField="end_qty" />
 </Columns>
</asp:GridView>

Open in new window

0
Comment
Question by:kishan66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
Tuyau2poil earned 500 total points
ID: 35089029
use OnRowDataBound event in gridview tag :

 <asp:GridView ID="pnlGrid" runat="server" OnRowDataBound="GVDatabound" ... etc...

and in code behind you can then do all you want with yours strings :

 Protected Sub GVDatabound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        If e.Row.RowType = DataControlRowType.DataRow Then

         dim start_qty  as string= e.Row.Cells(1).text

        e.Row.Cells(1).text = string.format("{0:N3}", start_qty )

        End If

    End Sub
0
 

Author Comment

by:kishan66
ID: 35090755
hi Tuyau2poil,
 i tried ur code ...though the function is getting called n executed.....output remains the same.(unformated).

sample values from XML ...are as follows.....
<start_qty>0.000000000000000e+000</start_qty>
<end_qty>0.000000000000000e+000</end_qty>
<unrealized>1.595800080000000e+004</unrealized>

As you can see, i want to convert these values to decimal currency, if possible
0
 

Author Comment

by:kishan66
ID: 35096052
oops !! i have to change from scientific to decimal..

now working ...
thanks Tuyau2poil:
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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