Solved

ASP.net DataGrid -- convert string to Int

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

26 Experts available now in Live!

Get 1:1 Help Now