Advertisements

Archive

Posts Tagged ‘vb.net’

GridView: Findcontrol from HeaderTemplate/ItemTemplate

September 19, 2017 Leave a comment

How to find item template control in GridView?

Dim chkHeader As CheckBox = DirectCast(gridView1.Row.FindControl(“chkHeader”), CheckBox)

How to find control from header template in grid view?

For example If you want to find checkbox available in header template of gridview

<asp:GridView ID=”gridView1″ runat=”server” AutoGenerateColumns=”False”><Columns>

<asp:TemplateField >

<HeaderTemplate>

<asp:CheckBox ID=”chkHeader” runat=”server” />

 </HeaderTemplate>

</asp:TemplateField >

</Columns>

</asp:GridView>

Solution:

Find Header control using following line of code

VB.NET Code:

Dim chkHeader As CheckBox = DirectCast(gridView1.HeaderRow.FindControl(“chkHeader”), CheckBox)

C# Code:

CheckBox chkHeader = (CheckBox)gridView1.HeaderRow.FindControl(“chkHeader”);

Hope this is help !

 

 

 

 

 

Advertisements

Is it possible to disable forms authentication for specific sub directories of an application?


Yes we can disable forms authentications for specific sub directory using below code in config files

<location path="Folder" allowOverride=”false”>
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
 Hope this help !

File Download code in vb.net


If Not String.IsNullOrEmpty(strURL) Then
Dim req As New WebClient()
Dim response As HttpResponse = HttpContext.Current.Response
response.Clear()
response.ClearContent()
response.ClearHeaders()
response.Buffer = True
response.AddHeader(“Content-Disposition”, “attachment;filename=””” + Server.MapPath(strURL) + “”””)
Dim data As Byte() = req.DownloadData(Server.MapPath(strURL))
response.BinaryWrite(data)
response.[End]()
End If

 

Hope it helps !

SalesForce (Login) Integration With ASP.NET

April 24, 2015 1 comment

Steps…

  1. Add Service Reference, select Advanced and then select Add Web Reference.
  2. In the URL box of the Add Web Reference dialog box, type the URL to obtain the service description of the XML Web service you want to access, such as:

    c:\Files\enterprise.wsdl

  3. Click Go to retrieve information about the XML Web service.
  4. In the Web reference name box, rename the Web reference to sforce, which is the name you will use for this Web reference.
  5. Click Add Reference to add a Web reference for the target XML Web service.
  6. Visual Studio retrieves the service description and generates a proxy class to interface between your application and the XML Web service.

Issues :

error CS0030: Cannot convert type ‘SFDC.ListViewRecordColumn[]’ to ‘SFDC.ListViewRecordColumn’
error CS0030: Cannot convert type ‘SFDC.ListViewRecordColumn[]’ to ‘SFDC.ListViewRecordColumn’
error CS0029: Cannot implicitly convert type ‘SFDC.ListViewRecordColumn’ to ‘SFDC.ListViewRecordColumn[]’
error CS0029: Cannot implicitly convert type ‘SFDC.ListViewRecordColumn’ to ‘SFDC.ListViewRecordColumn[]’

Solution:

Add following to enterprise.wsdl.xml

<xsd:attribute name=”tmp” type=”xsd:string”></xsd:attribute>

e.g.

<complexType name=”ListViewRecord”>
<sequence>
<element name=”columns” type=”tns:ListViewRecordColumn” maxOccurs=”unbounded”/>
</sequence>
<xsd:attribute name=”tmp” type=”xsd:string”></xsd:attribute>
</complexType>

Hope this help!

Deep and Shallow Copying, Difference of Shallow and Deep Copying

December 16, 2014 Leave a comment

What is Shallow Copy?

Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.

What is Deep Copy?

A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.

When creating copies of arrays or objects one can make a deep copy or a shallow copy. This explanation uses arrays.

Recall array variables in Java are references or pointers. A shallow copy can be made by simply copying the reference.

public class Ex{
private int[] data;

public Ex(int[] values){
data = values;
}

public void showData(){
System.out.println( Arrays.toString(data) );
}
}

The above code shows shallow copying. data simply refers to the same array as vals.

Shallow

This can lead to unpleasant side effects if the elements of values are changed via some other reference.

public class UsesEx{
public static void main(String[] args){
int[] vals = {-5, 12, 0};
Ex e = new Ex(vals);
e.showData(); // prints out [-5, 12, 0]
vals[0] = 13;
e.showData(); // prints out [13, 12, 0]
// Very confusiin, because I didn’t intentionally change anything about the
// object e refers to.
}
}

A deep copy means actually creating a new array and copying over the values.

public class Ex{
private int[] data;

public Ex(int[] values){
data = new int[values.length];
for(int i = 0; i < data.length; i++)
data[i] = values[i];
}

public void showData(){
System.out.println( Arrays.toString(data) );
}
}

The above code shows deep copying.

deep

Changes to the array values refers to will not result in changes to the array data refers to.

How to check if the user enters the default datetime? VB.NET


In VB.NET if we pass nothing to date it will return default value like ” #12:00:00 AM# ‘

 

To check if date is not default date than following should be used

IfNotDate.MinValue = MyDate

 

Hope it helps

Categories: VB.NET Tags: , , ,

Proper case in vb.net

December 12, 2013 Leave a comment

Convert a String to Uppercase

The String class has a static method named ToUpper. You can use this method to convert a string to uppercase. You can also use the UCase or StrConv function. For example:

    Dim upper as String = "converted from lowercase"
    Console.WriteLine(upper.ToUpper())
    Console.WriteLine(UCase(upper))
    Console.WriteLine(StrConv(upper,VbStrConv.UpperCase))

Convert a String to Lowercase

The ToLower method is the complement of the ToUpper method. ToLower converts a string to lowercase. You can also use the LCase or StrConv function. For example:

    Dim lower as String = "CONVERTED FROM UPPERCASE"
    Console.WriteLine(lower.ToLower())
    Console.WriteLine(LCase(lower))
    Console.WriteLine(StrConv(lower,VbStrConv.LowerCase))

Convert a String to Title Case

To convert a string to title (or proper) case, pass the string to the StrConv function with a constant that identifies the operation to be performed. For example:

Dim title as String = "converted to title case"
    Console.WriteLine(StrConv(title, VbStrConv.ProperCase))

Convert String Using the TextInfo Class

This section describes how to use the TextInfo class to convert strings. Because you can use the conversion methods inTextInfo to control culture information, you may want to use this class when you need to specify particular culture settings.

TextInfo is member of the System.Globalization namespace. TextInfo provides the ToUpperToLower, and ToTitleCasemethods for conversion to uppercase, lowercase, and title case respectively. Unlike the methods of the String class, theTextInfo methods are not static methods and require an instance of the class.

In most situations, you can default to the culture that is currently in use. Culture information is a property of the thread on which the code is running. To obtain the culture information, you must gain access to the current thread and retrieve theCurrentCulture property from that thread. Once you accomplish this, you can create the TextInfo object. For example:
    Dim curCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
    Dim tInfo As TextInfo = curCulture.TextInfo()
The following code sample illustrates how to call the three string conversion methods of the TextInfo class:
Dim title as String = "converted using textinfo"
    Console.WriteLine(tInfo.ToTitleCase(title))
    Console.WriteLine(tInfo.ToLower(title))
    Console.WriteLine(tInfo.ToUpper(title))
				
Example :

Imports System.Globalization
Imports System.Threading
Module Module1

    Public Sub main()

        Dim title As String = "this is my converted string"

        Console.WriteLine("Built-in Methods")
        Console.WriteLine("----------------")
        Console.WriteLine(UCase(title))
        Console.WriteLine(LCase(title))
        Console.WriteLine(StrConv(title, VbStrConv.UpperCase))
        Console.WriteLine(StrConv(title, VbStrConv.LowerCase))
        Console.WriteLine(StrConv(title, VbStrConv.ProperCase))
        Console.WriteLine()

        Console.WriteLine("String Class")
        Console.WriteLine("------------")
        Console.WriteLine(title.ToUpper())
        Console.WriteLine(title.ToLower())
        Console.WriteLine()

        Console.WriteLine("TextInfo Class")
        Console.WriteLine("--------------")
        'Get culture information from current thread.
        Dim curCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
        'Create TextInfo object.
        Dim tInfo As TextInfo = curCulture.TextInfo()
        'Convert to uppercase.
        Console.WriteLine(tInfo.ToUpper(title))
        'Convert to lowercase.
        Console.WriteLine(tInfo.ToLower(title))
        'Convert to title case.
        Console.WriteLine(tInfo.ToTitleCase(title))
    End SubEnd Module