Solved

ASP.net DataGrid -- convert string to Int

Posted on 2011-03-09
3
433 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now