.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

DayOfWeekEnum - get day value given an integer

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
Hi, I want to retrieve the text as 'Sunday', 'Monday' when the day values is given as an integer such as 1,2,...etc... Without using swich-case, how do I do this using DayOfWeek enum?   Thanks for any response

View Complete Post

More Related Resource Links

Integer Validation



I need to make validation for Textbox to allow enter integer stated by 9 or 6 or 5 , and also maximum 8 digits , how to do that ?





How to cast integer values as an array of enum values?


Hello all!

I'm working with VS2010 Beta2, ASP.NET and Dynamic Data. I'm using VB but will certainly be happy to receive a C# example if necessary. Laughing

I used a few of Steve's examples (Writing Attributes and Extension Methods for Dynamic Data and Dynamic Data - Hiding Columns in selected PageTemplates) to create a custom property attribute to be applied to a dynamic data column and want it to accept an array of enum values (each value will represent a dynamic data page template where this column should not be displayed).  My new attribute works fine when I hardcode it like this, meaning the HideColumnIn attribute is properly populated with the array of enum values:

<HideColumnIn(PageTemplate.List, PageTemplate.Edit)> _
Public Property My_DD_Column As Object


However, I want to store the values to be used for the HideColumnIn in the DB as integer values that correspond to the

Creating an integer only textbox control

Hi all I was wondering on how to create an integer only textbox control. Im close I just cant figure out why its not working. public partial class IntegerTextBox : TextBox { public IntegerTextBox() { } private void OnTextChanged(KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) e.Handled = true; } }

Integer Value of 80 being returned as 20480

I'm writing an applicaiton that lists all of the ports of existing processes on the system.  However the system is returning the value of 20480 as the value for port 80.  I've found a couple of articles that would indicate that the discrepancy is because of the "endianess" of the underlying system and that reversing the byte order would resolve the problem.  However when I convert the return value to an array of bytes the values show up as 0,80,0,0.  Even reversing the order of the bytes wouldn't return the appropriate value of 80. Specifically I'm calling into the iphlpapi.dll using the following function [DllImport("iphlpapi.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]         private static extern int GetExtendedTcpTable(IntPtr pTcpTable, ref int dwOutBufLen, bool bOrder, int dwFamily, TCP_TABLE_CLASS dwClass, int dwReserved); Here's some additional code from the listing this.m_TcpTable.Add(new TcpEntry(entry.dwState, entry.dwRemoteAddr, entry.dwRemotePort, entry.dwLocalAddr, entry.dwLocalPort, entry.dwProcessId)); public TcpEntry(TcpState state, UInt32 remoteAddr, int remotePort, UInt32 localAddress, int localPort, int processID)         {             this.m_State = state; &nb

Need help using the integer ID assigned in another field

Hi, My table stores information about files stored in the file system. I need to use the ID assigned by the database (primary key) in the file name. Is there a way to use the ID being assigned in the INSERT statement or will I have to make an INSERT statement, then get SCOPE_IDENTITY(), then do an UPDATE? Table looks something like this: FileID int (PK) FileName varchar(250) Here's an example of what I'm trying to do: INSERT INTO MyFiles (FileName) VALUES (-- ??? Not sure what goes here) Thanks, Sam

Value changing to integer value when changing top drop down box from cascaded drop downs in Sharepoi

Hi, I have two drop down boxes named Categories and Sub Categories. When I select a category, the sub category populates fine and I can select the values where the category is equal to the category lookup field. But as soon as I then change the Category field again once I have selected both the category and sub category fields, the sub category field changes to an integer value? How can I change this so it just selects the blank value again?

Convert integer to binary using asp.net

Hi I have an Integer value as 15, i want to convert as binary value. please guide me.   Thanks S.Andrews  

How to cast integer values to an array of enum values?

Hello all! I'm new to VB.NET (and OOP in general) and am struggling a bit...  I'm working with VS2010 Beta2, ASP.NET and Dynamic Data, however I'm thinking this question may be more related to VB so hopefully I've chosen the correct forum. I have a list of integer values stored in the DB and would like to cast them to an array of enum values so that they may be passed to my constructor.  The values in the DB directly correspond to the enum values.  Here is stripped down version of the code that hopefully highlights what I'm attempting to do:Private _pageTemplate() As PageTemplate Public Sub New(ByVal ParamArray pageTemplateArray As PageTemplate()) _pageTemplate = pageTemplateArray End Sub Public Enum PageTemplate Details = 1 Edit = 2 Insert = 3 List = 4 ListDetails = 5 End Enum What I'm having difficulty with is reading integer values from the DB and casting them to an array of PageTemplate() to be passed to the constructor above.  The integer values in the DB will be 1 through 5 to correspond to the enum values listed above.  Here is how I'm trying to build the ParamArray to be passed to the attribute constructor:Dim hideFieldsIn(-1) As PageTemplate Dim rowCount As Integer = -1 If reader.HasRows Then While reader.Read() rowCount += 1 ReDim hideFieldsIn(rowCount)

create integer range from 1 to 100

I want to create a dynamic integer that makes a new integer for every number from 1 to 100

convert Label text to integer

Hi, I want to convert Label text into Integer datatype.  I tried by giving Convert.Int32(Label1.Text) and int.Parse(Label1.Text)  but I couldn't do Type casting . I am getting error at runtime.    I searched in web I couldn't get the solution. Please help me....

HowTo Marshal C++ enums and copy buffer of unsigned 16bit integer


Hi together,

I'm trying to wrap an API of a digital camera SDK (unmanaged C++). Some of the functions a working, but some of them ... :(

1. HowTo marshal  C++  enums?

This is a part of the api.h file:



	DCAM_DATATYPE_UINT8	=	0x00000001,	/* bit 0 */
	DCAM_DATATYPE_UINT16	=	0x00000002,	/* bit 1 */
	DCAM_DATATYPE_UINT32	=	0x00000008,	/* bit 3 */
	DCAM_DATATYPE_MOSAIC8	=	0x00010000,	/* bit 16, 8bit mosaic */
	DCAM_DATATYPE_MOSAIC16	=	0x00020000,	/* bit 17, 16bit mosaic */
	DCAM_DATATYPE_RGB24	=	0x00040000,	/* bit 18, 8bit*3, [ r0, g0, b0], [r1, g1, b1] */
	DCAM_DATATYPE_RGB48	=	0x00100000,	/* bit 20, 16bit*3, [ r0, g0, b0], [r1, g1, b1] */


BOOL DCAMAPI dcam_getdatatype			( HDCAM h, DCAM_DATATYPE* pType );
BOOL DCAMAPI dcam_setdatatype			( HDCAM h, DCAM_DATATYPE type );<br/>


And this is what I wrote in C#:

Problem with InfoPath 2007 Form opened with InfoPath 2010 - whole number integer not coming into dat


I found an issue when testing existing InfoPath 2007 forms via the Infopath 2010 Designer client.  Integer fields in the form template are publishing to a SharePoint Forms Library and show in the default view.  However, if that library is then used as a Data Connection in another or same form template those integer fields are not displaying or available for selection. 

This is not a problem using the InfoPath 2007 client.  It is not an option to convert the field to text as it could affect existing forms in existing libraries.  Also, existing integer fields are no longer appearing in previously defined SharePoint-based secondary data connections.  Only the ID field still appears.  But, those existing fields still work in the form and are selectable for functions, etc.

Is there a solution to this?

Thanks much!  Mike - www.ProgramNetInc.com


How can we identify data is integer or not


Can we  identify if a data value is an integer using query.

Best way to avoid error message due to null vs integer incompatibility


I receive the error message below, I think because the database field in question is null (I realize I probably should not allow null values, but I can't even display the page to allow the user to enter a value---and I would prefer not to enter a default value in SQL).

How do I avoid this error message? If the column is null (and it is supposed to be an integer), do I need to change the value to something like "0" in the code behind---or is there any easier way to do this right in aspx page (see source of error message below)?  Either way, I'm not sure how to do either (I can't get any such lines of code to work here). Thank you.


Object cannot be cast from DBNull to other types.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.

Source Error:

Line 50:  <td><ItemTemplate>
Line 51:    <asp:Label ID="PriceLabel" run

Using DataAnnotations to verify integer


I am using Entity Framework with partial classes added on so I can use DataAnnotation attributes.  Does anyone know how to add a data annotatin which will verify that a field is a whole number (or a DataType of int or long)?  I'm surprised there is no [DataType(DataType.Integer)] attribute.  I tried to create a custom attribute, but it doesn't work because the value it receives is always null:

[DataTypeWholeNumberAttribute(ErrorMessage = "Zip must be a whole number")]
public object Zip{ get; set; }

public class DataTypeWholeNumberAttribute : ValidationAttribute
    public override bool IsValid(object value)
       long i;

        if (value == null) //value is always null.
            return false;

        return Int64.TryParse(value.ToString(), out i);

Obviously I'm missing the point, but I don't know enough to know what I'm missing.  Can anyone shed some light?

Split the integer value form text


 I have a @message parameter in SP, user sends an Integer value in that message.
For Ex: @message = 'This is, a Test message 500000 and the message ends.'
Now i want to get only that 500000 value from this @message param. There is no delimiters for identifying the integer value and in that param contains only one integer value

create procedure st_test (@message varchar (4000), @result int output)
//LOGIC for get the interger value

geting string from integer using enums


we know 

The .NET Framework contains an Enum called DayOfWeek.

so now if i have an integer 7
how can i ge the string "Saturday" using  the enum

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend