vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Tuesday, February 28, 2012

Apply sorting in gridview using asp.net


Introduction:
In this article you have seen about to do sorting in gridview.
Description:
In a previous article already I discussed about to how to edit and load in gridview and sorting in datatable. For your reference here i mention the previous link...



For doing sorting in gridview you have to do the list of things.
Initially you have to add AllowSorting ="true" in gridview
Add the sort expression in every bound filed or template field in grid view..
Add the below code in GridView1_Sorting event in gridview..

<asp:gridview id="GridView1"
             autogeneratecolumns="False"
       autogenerateselectbutton="false"
       allowpaging="True"
       selectedindex="1"
        AllowSorting ="true"
            runat="server">
         <Columns><asp:TemplateField > <ItemTemplate>
                  <asp:BoundField DataField="Name"
                 HeaderText="Name"
                 InsertVisible="False" ReadOnly="True"
                 SortExpression="Name"    />
             <asp:BoundField DataField="Address"
                 HeaderText="Address"
                 SortExpression="Address" />
                     </Columns></asp:gridview>

Initially i stored sort expression in viewstate .For an every click its has sorting ascending or descending order

Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        Dim dt1 As DataTable = GridView1.DataSource
         If dt1.Rows.Count > 0 Then
//Create new dataview instance and pass datatable
            Dim dtview As New DataView(dt1)
  //Sort dataview data based on the sort directin value
           dtview.Sort = e.SortExpression & " " & chksorting(If(ViewState("ord"), "ASC"))
            GridView1.DataSource = dtview
            GridView1.DataBind()
        End If
     End Sub
    Function chksorting(ByRef srt As String) As String
        Dim srtgrid As String
        Select Case srt
//If previous sort direction if ascending order then assign new direction as descending order
            Case "ASC"
                srtgrid = "DESC"
//If previous sort direction if descending order then assign new direction as ascending order
            Case "DESC"
                srtgrid = "ASC"
         End Select
        ViewState("ord") = srtgrid
        Return srtgrid
    End Function

Conclusion:
Here you learned do sorting in grdview using dataview.
Post your comments here..Happy coding

Friday, February 24, 2012

Resize the image using Ajax Slider Extender


Introduction:
Here we resize the image width, height using Ajax slider extender

Description:

In an previous article I wrote about how to use of slider extender and how to apply css for slider extender..



By using simple code we can easily resize the image width and height using slider extender with java script. This type method can be use to zoom image.

Here it’s very interesting to work on JavaScript..i apply the script on textbox change event..
Here when we move the slider control the text box value has changed ,When the textbox value has changed the script can be called and apply size value to image control..
Code:
<div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <table>
        <tr>
        <td>
        Change image height:
         <asp:TextBox ID="TextBox1" runat="server" onchange="hgh();" Text="100"></asp:TextBox>
        </td>
        <td>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        </td>
        </tr>
        <tr>
        <td>
        Change image width:
        <asp:TextBox ID="TextBox3" runat="server" onchange="wdt();" Text="100"></asp:TextBox>
        </td>
        <td>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        </td>
        </tr>
        </table>
     </div>
    <div>
    <asp:SliderExtender ID="SliderExtender1" runat="server" TargetControlID ="TextBox1" BoundControlID ="TextBox2" Minimum ="0" Maximum ="300" RaiseChangeOnlyOnMouseUp ="false" >
    </asp:SliderExtender>
    </div>
    <div>
    <asp:SliderExtender ID="SliderExtender2" runat="server" TargetControlID ="TextBox3" BoundControlID ="TextBox4" Minimum ="0" Maximum ="300" RaiseChangeOnlyOnMouseUp ="false">
    </asp:SliderExtender>
    </div>
    <div>
        <asp:Image ID="Image1" runat="server" ImageUrl ="images/k1.jpg"/>
    </div>

Add the JavaScript code 
<script type="text/javascript" >
        function hgh() {
            var ht;
            ht = document.getElementById("TextBox1").value;
            document.getElementById("Image1").height = ht;
        }
        function wdt() {
            var wh;
            wh = document.getElementById("TextBox3").value;
            document.getElementById("Image1").width = wh;
        }
    </script>


Conclusion
In this article u learned about to apply image height and width using slider extender..
Post your valuable comments..

Wednesday, February 22, 2012

VB.NET Golden Rules


The purpose of this article is to provide coding style standards for the development source code written in VB.NET. These is the best practice to follow the below standard forever in your vb.net.

The following guidelines are applicable to all aspects VB.NET development:

o  Make code as simple and readable as possible. Assume that someone else will be reading your code.
o  Prefer small cohesive classes and methods to large monolithic ones.
o  Use a separate file for each class, struct, interface, enumeration, and delegate with the exception of those nested within another class.
o  Turn Option Explicit and Option Strict on for every project under Project | Properties | Common Properties | Build. These can be made the default options for all new projects by going to Tools | Options | Projects | VB Defaults.
o  Don’t use the On Error Goto or  On Error Next statements. Use structured exception handling via Try/Catch blocks instead. They are the preferred method of performing error handling in .NET.
o  Write the comments first. When writing a new method, write the comments for each step the method will perform before coding a single statement. These comments will become the headings for each block of code that gets implemented.
o  Use liberal, meaningful comments within each class, method, and block of code to document the purpose of the code.
o  Mark incomplete code with ‘ TODO: comments. When working with many classes at once, it can be very easy to lose a train of thought.
o  Never hard code “magic” values into code (strings or numbers). Instead, define constants, static read-only variables, and enumerations or read the values from configuration or resource files.
o  Use the StringBuilder class and it’s Append(), AppendFormat(), and ToString() methods instead of the string concatenation operator (+=) for large strings. It is much more memory efficient.
o  Be sure Dispose() gets called on IDisposable objects that you create locally within a method. This is most commonly done in the Finally clause of a Try block. It’s done automatically when a Using statement[1] is used.
o  Never present debug information to yourself or the end user via the UI (e.g. MessageBox). Use tracing and logging facilities to output debug information.
I hope you like this article..Also please share your thought about rules must follow in .net


Monday, February 20, 2012

Apply CSS style for gridview pager in asp.net


To apply style in gridview paging need a simple code with css. By using CSS we can easily apply any type of style to gridview paging.

Here i share a simple style css code for gridview..from this one you can change any style as you like..
.grid_paging a
{
     text-decoration: none;   }
.grid_paging a:hover
{
    text-decoration: underline;     }
.grid_paging a:link
{
   font-size: 15px;
    padding: 2px 6px;
    background-color :#EBECEE;
    border: 1px solid #B5BAC0;    }
.grid_paging span
    {            background-color: #263441;
            border: 1px solid #DBEAFF;
            color: #FFFFFF;
            padding: 2px 5px;    }

You must add the code in your CSS file..Then call the css in page footer style like below..


 <PagerStyle CssClass="grid_paging" />

i hope you like it...have a Happy day.

Friday, February 17, 2012

Maintain Scrollposition onpostback in asp.net


Introduction
Here you ll see about how to maintain the scroll position during postback in asp.net..

Description:

Normally when doing any click event (postback occur)  then scroll position was moving to top of the page.
For some instance we need to maintain the position at the same place. Regarding this issues i wrote some article in previous post.



But in this case we need to add attribute in the page directives. Its presence in the top of the page in client side.....
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" MaintainScrollPositionOnPostback ="true" Inherits="test" %>


Now on every postback the scroll position has been maintained in the same position.

I hope  this articles helps u..

Tuesday, February 14, 2012

Split the fractional number in a string using regular expression


Introduction:

In this article you're going to see about split fractional number in a string variable.
Description:
If you need search or split only fractional number in a string then you can use following regular expression method.

By using regex you can find anything you want...but only thing you need to know how to use and write the regex expression.
Some useful characters used in Regex expression:
[ ]  Used to match anything inside the square brackets for example [0-9] it match any character between 0 to 9

Code:
Dim str As String = "abcdefgh99.99ghtiojkj45678thyo899.00"

        Dim t1 As New List(Of String)
        Dim t As MatchCollection
        t = Regex.Matches(str, "[-+]?[0-9]*\.?[0-9]+")

        For Each itm As Match In t
            t1.Add(itm.Value)
        Next

Finally t1 has contains only the value 99.99,4567 and 899.00

I hope you enjoy this code……..

Book online iberry tablet pc with android v 4.0


ImageIberry tablet pc price is start from the price 6990 on wards..

Initially they have 3 types of model available for market in different type of features

The device will be based on Android 4.0 (Ice Cream Sandwich) operating system and will be capable of handling up to 32 GB of expandable memory via microSD cards. Also the device will get mini USB on the go port support for pen drives and other peripherals.

iBerry is all set to launch the device countrywide in the next month. Auxus AX02 will be available through the online retail network and retail sale partners in various cities across India. The company is offering a one year comprehensive warranty for the devices, which will be handled by the company's service network throughout India.

For Booking Online or Buy Online..

Monday, February 13, 2012

Show alert message from server side code or from inside update panel


Here if you want to show alert box from the server side code.Incase the button has inside the update panel you must follow this below code

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Key", "alert('alert box.');", true);

 In case if we want to redirect to another page after a showing alert message...Try this below code

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Key", "alert('alert box.');window.open('defult.aspx','_parent');", true);

VB Code:

ScriptManager.RegisterClientScriptBlock(Me, GetType(Type), "key", "alert('alert box.');window.open('defult.aspx','_parent');", True)


I hope you read something useful to u

Friday, February 10, 2012

Draw circle,Rectangle and line in vb.net using visual Basic power pack


Here you learn some interesting features about vb.net..In early vb 6 have the features of drawing line, circle and rectangle...But in after release of vb.net that cannot provide..But now by adding visual Basic power pack we can get the tools in vb.net.

To get the visual Basic power pack click the below link to download..


Once you download add the dll file..Right click toolbox, select choose item and browse the dll file and click ok..
Now the tools are added in your toolbox.

image

Then you must use the Namespace system. Drawing for access the controls.....
 image
I hope you enjoy this articles………..

Thursday, February 9, 2012

Store or import your bookmark into Delecious


Delecious:

Delicious is the place to collect and showcase your passions from across the web. Save your bookmark in your own ID, Also you can make your bookmark as public as well as private..
Here you can import you saved bookmark into delicious from your browser..So you can use at anywhere.

Chrome Browser:
Step 1:Go to: click Customize control
Step 2: select Bookmark ->and select Bookmark manager
step  3: click the button organize
Step 4: Then you can find the option Export Bookmark to HTML file
Create and store the bookmark html file in any folder..
Then open your delicious page sign in your account and Go to setting in the right side you can find the option import ..
Select the import and upload your created html bookmark file...that’s it.....

Now you can get your bookmark anywhere for your needs..

I hope you like this article......

Store or import your bookmark into Delecious:

Wednesday, February 8, 2012

C# 4, ASP.NET 4, and WPF, with Visual Studio 2010

C# 4, ASP.NET 4, and WPF, with Visual Studio 2010 Jump Start

This Wrox Blox is a value-packed resource to help experienced .NET developers learn the new .NET release. It is excerpted from the Wrox books: Professional C# 4 and .NET 4, Professional ASP.NET 4, and WPF Programmer’s Reference



Read line by line in a string variable using stream reader


Introduction:

Here I share bit of code, i searched recently for my need, it’s about to read data from string variable line by line.

Description:
I have a string its contains which number of line with passage..i need to read that string as line by line..
Normally stream reader used to read the lines form the specified path files like txt or any file...But if you pass the string variable directly to the stream reader it will throw an error..For that you need to convert the string into bytes then pass it to stream reader..
Dim reader As New StreamReader(New MemoryStream(Encoding.ASCII.GetBytes(passage.ToString())))


 lnr = reader.ReadLine

I hope u enjoy…

Friday, February 3, 2012

Read CSV files store into database or data table


Hi.
Introduction:
Here we discuss about to read CSV file and load into data table or store into database…
Description:

Its very easy methods to read CSV file and store..In many case we use reader to read file then we stored into data table…
Here we directly read the file into data table…Using this techniques..We improve the performance

Code:
String PATHFIL,strQuery;
        PATHFIL = "C:\736.csv"
       
        Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " & System.IO.Path.GetDirectoryName(PATHFIL) & "; Extended Properties = ""Text;HDR=YES;FMT=Delimited""")
        conn.Open()
        strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(PATHFIL) + "]"
        Dim ADAPTER As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(strQuery, conn)
       
        ADAPTER.Fill(DS)
        DT = DS.Tables(0)

Once we got all the data in data table..Then we can do, whatever we want..Either can store in database or do any manipulation….

I hope u spend some worth time …..

Wednesday, February 1, 2012

Display onmouse over effect on gridview in asp.net


Hi..

Introduction:

To apply gridview onmouseover row style. we follow this method…

Description:

Grid view has power full data control used in asp.net Before I wrote many articles about grid view..Still we must learn lot of things to know about grid view.
Here we shall learn about to apply onmouse over style on grid view..
To apply this style we write the code on Rowdatabound event..Its main event used to do anything on gridview.In previous article I wrote about rowdatabound event..
For your reference I mention the path here……


http://www.dotnetcode.in/2011/06/rowdatabound-event-in-gridview-using.html

If you would see my previous article you must well known about load and edit grid view..
To show mouse over style you need to write the bit of code in row databound event

If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FFFFE1';")
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E0E0E0';")
        End If


Thanks for reading hope you liked it..