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
Solved

ASP.net DataGrid -- convert string to Int

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp enable view state 1 28
Save ms data to server side. 19 55
Finding Events logs for IIS website that restarts 2 14
Easy filter aspnet 2 24
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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