GridView & FormView dropping leading zeros from numbers set as strings

I'm storing in a SQL database a certain field (an employee number) as a varchar data type. Throughout the app (datasource, update/insert stored procedures, etc.) I'm working with it as a string. I've even ensured that it's being used as a string "behind the scenes" by watching it in SQL Profiler.

Problem is, the GridView & FormView that display it always drop any leading zeros. Wierder yet, when I put the GridView in Edit mode & add a zero, it saves to the database with the zero, but the leading zero doesn't display in the GridView!

Anyone know how I can fix this?

Thanks!


"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
0
capella07
9/5/2008 4:23:12 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
734 Views

Similar Articles

[PageSpeed] 41
Get it on Google Play
Get it on Apple App Store

While waiting for the thread to get approved I did some more testing. I've seen some other threads here regarding dropped leading zeros, but I didn't find anything that helped.

Another thing of note, I have another page build very similarly to this one (in fact the one I'm having trouble with was actually the template for the second one!) and there are four fields that I can enter leading zeros in and they save & display as they should; which means I'm probably missing something somewhere, but I don't have a clue where to look - I THOUGHT I looked everywhere, but obviously not!!!

Help!
"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
0
capella07
9/5/2008 4:50:33 PM

Hi capella07,

I haven't met this issue in my testing so far, but I think you can format it in RowDataBound event:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lb = (Label)e.Row.FindControl("Label1");   //"Label1" is used to display "employee number" field
            lb.Text = int.Parse(lb.Text).ToString();
        }
    }

Thanks,


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Qin
9/10/2008 5:50:48 AM
Reply:

Similar Artilces:

Formview & nested controls & databinding (a.k.a Formview doesn't like nested controls)
I think I have found a bug in .Net 2.0 beta2.  I have spent days and days on this problem, and I hope that somebody else can help me out with this before I pull my hair out .  What I'm trying to do seems like it should be easy, but somehow it's not. If I create a formview control in Asp.Net 2.0 beta 2, and assign it a DataSourceID and then create a textbox inside that and then bind the text property of that textbox, everything works as expected: <asp:Button ID="Button1" runat="server" Text="New" /><asp:FormView ID="fv" runat="server" DataSourceID="ods" DataKeyNa...

Dropping leading zeros in a GridView nvarchar field
I have a GridView that displays a column where the data is an "nvarchar" type.  These values are numbers, but look like this: "001", "002", "009", "010", "011". I would like to trim off the leading zeroes in the displayed GridView.  I have experimented with using a DataFormatString, but that is not working, as the values are not numbers - they are strings, essentially.  I know I could modify my database to store integers (as all of these values are in fact, numbers), but that brings up another problem.  I have &...

How to set the number of displaying items on Drop down list control?
Hi,Suppose that there are 100 items bound in a drop down list control, how can  I set the 10 items to display on Drop down list control , and for other items, I can drow the bar on this control to see them?  Thanks. Hi, you could use a ListBox control and set its Rows property to the desired number of visible rows.     <asp:ListBox ID="myListBox" Runat="server" Rows="10"></asp:ListBox> If you have more than 10 items, a right-scrollbar will appear on the control.Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action Thanks for your...

Autocomplete dropping leading zeros from results string array
Hi all, I am using the autocomplete control to retrieve values from a DB. When i do a search on a string beginning with a 0 the 0 is dropped from the results shown on screen. I have debugged the GetCompletionList method and the returning string array definetly has the leading zero's. As far as i can tell it only happens with the 0 character.   Any one have any ideas? Cheers,P.S. I am using .net 2.0 with ajax extensions 1.0   Hi WhatStherush, It is a known issue, please add the return items like this, myList.Add("\""+dr.GetString(0)+"\"&quo...

Set number of controls within control
How does one generate a varible number of custom controls within another container control ie first control is label and textbox called x second control exposes a property of number_to_create this could be any number 5, 15, 100 is it possible to do this? can one dynamically create controls in a loop?   hello.   i don't see why that isn't possible. for instance, the data bound controls create controls dinamically according with the items that should be shown to the user.-- Regards,Luis Abreuemail: labreu_at_gmail.comEN blog:http://msmvps.com/blogs/luisabreu...

VB.net 2005 & GridView & HyperLinkField & click event
Gang:I am trying to click on a HLF in a GV; however, I am unable to capture the declaration/click event.If I throw a test button on the page, the code behind for that click event fires off the code.How do I capture the click event for the HLF in the GV? What declaration/event am I trying to capture?A+ BS MCSE OOP Security+ Web DeveloperGet creative, not even. Hey,You can't capture the click event for HyperlinkField; HyperLink controls don't have a click event.Brian"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, ...

Set Datasource to Drop Down Control in FormView InsertTemplate Field through Code Behind
Hey , How do I set Datasource to Drop Down Control in FormView InsertTemplate/EditItemTemplate Field through Code Behind. I need this as we use general connection objects and general data retrival methods in a common Data Class. Please help? Thanks, Shyam Hi, raghavashyam: You just need to bind the datasource to the FormView(Containers) and the syntax as following in the templateFiled will bind the particlar filed to your controls.  <asp:TemplateField HeaderText="Name" >               &nb...

gridview/Formview with a datetime control parameter
I have a gridview that is the master and a formview that shows the details of the selected row of the gridview.  When a row of the gridview is selected, the formview datasource is retrieved from the database using the gridview selected host value and timestamp value.The sqldatasource for the formview is not working for me.  It has a datetime conversion error. Exception Details: System.FormatException: The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.   How should I code the control parms on the formview sqldatasource? Gr...

Adding a user control to FormView and setting a bind for the control
I have created a user control called PartialDate which holds three text boxes (one for Day, Month, and Year). The Partial Date user control also has the following property [Bindable(true, BindingDirection.TwoWay)]public MultipartDate mpDate{     get     {          MultipartDate mpd = new MultipartDate();          mpd.Day = this.getDay();          mpd.Month = this.getMonth();      &nb...

Drag & Drop other web controls to a composite control
Hi allI´m working on a GroupBox control and wonder if anyone know how I should do to make it possible to drag other web controls on it (just as if it was a System.Windows.Forms.GroupBox). Best RegardsMikael Håkansson I think it will suffice if you set the ParseChildren attribute to False. See http://msdn.microsoft.com/library/en-us/cpguide/html/cpconusingparsechildrenattribute.asp Jos...

GridView & OnRowUpdating & no control in a proper row
I have the following ASPX:<asp:GridView ID="ctlAllocations" runat="server" OnRowDeleting="ctlAllocations_OnRowDeleting" OnRowCommand="ctlAllocations_OnRowCommand" OnRowCancelingEdit="ctlAllocations_OnRowCancelingEdit" OnRowEditing="ctlAllocations_OnRowEditing" OnRowUpdating="ctlAllocations_OnRowUpdating" OnRowUpdated="ctlAllocations_OnRowUpdated" OnRowDataBound="ctlAllocations_OnRowDataBound" > <Columns> <asp:TemplateField HeaderText="GL Account" HeaderStyle-Horizontal...

Autocomplete dropping leading zeros and trailing zeros after a hyphen
Autocomplete Web Service Code 1    Imports System.Web2    Imports System.Web.Services3    Imports System.Web.Services.Protocols4    Imports System.Data.SqlClient5    Imports System.Data6    7    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.8    <System.Web.Script.Services.ScriptService()> _9    <WebService(Namespace:="http://tempuri.org/")> _10   <WebServiceBindi...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Cascading Dropdown error in formview controls and finding all controls in formview controls
can help with the following? Instantiate Cascading Dropdowns within Formview controls (this returns the error message "databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control".) Pass values between controls within master controls such as Textboxes within formviews (example: Pass the selected value in a dropdownlist to another textbox both WITHIN a formview control) Expose the public properties of a master page Hi arraybiz, 1) I need your code. See sample: http://www.mikepope.com/blog/fun/cascadingdropdowns_dy...

Web resources about - GridView & FormView dropping leading zeros from numbers set as strings - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 12/15/2015 6:32:05 AM