Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.net DataGrid -- convert string to Int

Posted on 2011-03-09
3
Medium Priority
?
474 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 2000 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

Technology Partners: 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

597 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