Thursday, July 30, 2009

merge the header row for the GridView control

some time we want to merge the Gridview Content as well as the Header also ,it was very easy in html you need to simply add the Colspan attribute and with the help of that you can set is (2, 3 )what ever you want.

Here is the way you can do that same thing in C#


<asp:gridview id="GridView1" runat="server" allowpaging="True" autogeneratecolumns="False"
datakeynames="ProductID" datasourceid="SqlDataSource1" onrowdatabound="GridView1_RowDataBound">
<columns>
<asp:boundfield datafield="ProductID" headertext="ProductID" insertvisible="False"
readonly="True" sortexpression="ProductID" />
<asp:boundfield datafield="ProductName" headertext="ProductName" sortexpression="ProductName" />
<asp:boundfield datafield="CategoryID" headertext="CategoryID" sortexpression="CategoryID" />
<asp:boundfield datafield="CategoryName" headertext="CategoryName" sortexpression="CategoryName" />
</columns>
</asp:gridview>
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
selectcommand="SELECT [ProductID], [ProductName], [CategoryID], [CategoryName] FROM Product_Details">
</asp:sqldatasource>




and here is CODEBEHIND Source



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow gvr = e.Row;

if (gvr.RowType == DataControlRowType.Header)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);

TableCell cell = new TableCell();
cell.ColumnSpan = 2;
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Text = "Product";
row.Cells.Add(cell);

cell = new TableCell();
cell.ColumnSpan = 2;
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Text = "Category";
row.Cells.Add(cell);

GridView1.Controls[0].Controls.AddAt(0, row);
}
}

jQuery Lightbox-Clones Plugin

1.jQuery FancyZoom


$(document).ready(function() {
$('a.zoom').fancyZoom();
});


here is a Zoom Effect plugin , this will shows the Content realted with the id Refrence and

the href of the mention tag.

DEMO

DOWNLOAD Here


2.FancyBox

FancyBox is one of the Great among Lightbox clones. its also very easy and smooth in

animation. there are some cool animation Effects:
- you can easity cutomize it
- you can also group realted item

here is sample code to do so.

$(document).ready(function() {
$("p#Ver1 a").fancybox();
$("p#Ver2 a").fancybox({ 'hideOnContentClick': true });
$("p#Ver3 a").fancybox({
'overlayShow': true,
'zoomSpeedIn': 0,
'zoomSpeedOut': 0

});
});


DEMO

DOWNLOAD Here


3. Pirobox
this is also cool and with more features.
but before that download the below dependancies

1. css_pirobox/pirobox.css
2. pirobox_packed.js
3. js/jquery1.2.6.js

DEMO
DOWNLOAD Here


4.ThickBox

thickBox is a UI dialog widget which is written in a Javascript , with cool feature in that you can show single image, multiple image, inline image and so on other feature

Feature : -
1 - Thinkbox was build with LightWeight Jquery Library
2 - Hide form elements in IE 6
3 - You can easily resize also.

DEMO
DOWNLOAD Here


5.NyroModal

Feature : -

1 - Ajax call
2 - Form
3 - Iframe
4 - Manual call
5 - Error Handling
6 - Esc key to exit

DEMO
DOWNLOAD Here


hope u like this collection , if u found out more then plz reply here or feel free to drop an comments

Wednesday, July 29, 2009

Select Recods from Checkbox and Preform operation Delete or Move .

hi,
again i come up with new tricks of GridView in that you can Delete / Update / Move
seleted records from Gridview, take a Example of Gmail inbox it shows total number of mail on your "Inbox" in that have a option like Delete , move to another folder , Delete all , and so on, same feature you can add in your Gridview

look at the Below Example hope u like it .
Steps
1.using javaScript we can select Or deselect the record from GridView


<asp:GridView ID="GridView1" datakeyname="Mailid" runat="server"

DataSourceID="Sqldatasource1">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckAll" runat="server" onclick="return check(this);"/>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="MailID" runat="Server"
Text='<%# DataBinder.Eval (Container.DataItem, "MailID") %>'
/>
<asp:CheckBox ID="DeleteRec" runat="server" onclick="return check(this);"/>
</ItemTemplate>
</asp:TemplateField>

</asp:GridView>
<asp:SqlDataSource ID="Sqldatasource1" runat="server"
SelectCommand="Select MailId,MailBody,Date,To,From from MailInbox"
ConnectionString="Server=MailEngine;uid=sa;password=;database=Inbox">
</asp:SqlDataSource>



2. we have Button Which act as a Delete /Move / Upadate Operation.

<asp:Button ID="Button1" OnClientClick="return confirmMsg(this.form)"
Text="Move" OnClick="Button1_Click" runat="server" />



3. Javascript code which can check the if any of Coloum get Select or Deselected.


function check(Val)
{
var MailChecked = Val.checked;
var MailId = Val.id;
var frm = document.forms[0];

// Loop through all Records in GridView

for (i = 0; i < frm.length; i++)
{
// Also Check if the Heder Template Option get Checked or Not
if (this != null)
{
if (MailId.indexOf('CheckAll') != - 1)
{
// Now check if Header template checkbox is Checked so it will Delete/Move all the

Records ,
// Then select or deselect datagrid checkboxes
if (MailChecked)
frm.elements[i].checked = true;
else
frm.elements[i].checked = false;
}
else if (MailId.indexOf('DeleteRec') != - 1)
{
// Check if any of the checkboxes are not checked,
and then uncheck top select all checkbox
if (frm.elements[i].checked == false)
frm.elements[1].checked = false;
}
}
}
}



4.Now we can Configure Move/Delete Configration Message .

function confirmMsg(frm)
{
// Now Again gone through the All the Gridview Elements
for (i = 0; i < frm.length; i++)
{
// Check for checkboxes only
if (frm.elements[i].name.indexOf("DeleteRec") != - 1)
{
// Show Alert message to End user to Really want to Delete / Move .
if (frm.elements[i].checked)
return confirm('Do you really want to Move/Delete Seleted Item')
}
}
}



5. on CodeBehind Button1_Click Event Perform the Action.

protected void Button1_Click(object sender, EventArgs e)
{
bool chkBox = false;
string GvID = "";

//Check each row in GridView for Select ot not.

foreach (GridViewRow gv in GridView1.Rows)
{
CheckBox MoveSelectedCheck = (CheckBox)gv.FindControl("DeleteRec");
if (MoveSelectedCheck.Checked)
{
chkBox = true;
// add the Seleted item with (;) so it can delete that or Move that
GvID += ((Label)gv.FindControl("MailID")).Text.ToString() + ",";
}
}

SqlConnection conn = // Define Connection String.
if (chkBox)
{
try
{
// Suppose Folder name or Lable name is (OldMail)
string MoveRec = "Update MailBox set Label ='+ OldMail +' where MailID IN (" +
GvID.Substring(0, GvID.LastIndexOf(",")) + ")";
SqlCommand cmd = new SqlCommand(MoveRec, conn);
conn.Open();
cmd.ExecuteNonQuery();
GridView1.DataBind();
}
catch (SqlException err)
{
Response.Write("Error at :-"+err);
}
finally
{
conn.Close();
}

}
}



Like this you can Perform Deletion or Updataion or Moving Oepration ,
if you are Deleting Records then its very easy you can use Delete query
if it is Updation use Update query .But in the case of Moving just like (Gmail inbox ) you have one option you can set the Status of that Seleted Mail as (Name of Folder) just like (Label part in Gmail )

and when you get click on that lable do code such that, Check if the any records from Gridview are Marked as (Lable name ) and you query according to same.

plz comment on it , if u have any query .......
Happy coding,

Parsing RSS feeds with XMLHttpRequest Object

You can parse RSS feeds with thehelp of XMLHttpRequest Object means using javascript or ajax

or jquery . what you have to do in this case is ones you ot the Xml Object you can traverse it

via DOM (Document Object Model).

here is some example which shows how u can done xml Parsing


<script type="text/javascript" language="javascript">
var XMLObjString = '\
<rss version="2.0">\
<channel>\
<title>Test</title>\
<link>http://www.xyz.com/</link>\
<description>RSS Feed</description>\
<language>EN</language>\
<image>\
<url>http://www.xyz.com/images/test.gif</url>\
</image>\
<category>JavaScript</category>\
<item>\
<title>5:20 PM 7/28/2009</title>\
<link>http://www.xyz.com/index.html</link>\
<description>
This is index page | Message at : 5:24 PM 7/28/2009
</description>\
</item>\
</channel>\
</rss>';


// Now convert string to XML object

var xmlobj = (new DOMParser()).parseFromString(XMLObjString, "text/xml");

// set the reference to the root-element "rss"
var root = xmlobject.getElementsByTagName('rss')[0];

// like that you can set reference to "channel" element
var channels = root.getElementsByTagName("channel");

// find all the "item" tags in the channel
var items = channels[0].getElementsByTagName("item");

// in the "item" find the Description to get the Desc also.
var descriptions = items[0].getElementsByTagName("description");


// you can also get the actual description as string
var desc = descriptions[0].firstChild.nodeValue;

// now split the string - description is element

var Descarray = desc.split("|");
var Message = Descarray[1];

// now we have the RSS data we want as strings
alert(Message);

</script>


Now you can get the data at "alert(Message); tag you can use it whenever you want

Tuesday, July 28, 2009

Jquery form Post request

hi , i have seen this on many website without refreshing a webpage directly value get upadted
how it can be happen? yes its possble with the AJAX / Jquery because it use XMLHttpRequest Object

here is my Example on how you can achive this using Jquery

Steps

1. Add the Jquery liblary in <head> Section
you can download jquery library from here

2. now supoose if we change the price from dropdown the Event should occur .


<select name="Price" id="Price" onchange="update()">
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
</select>


3. Now create a function update()

function update()
{
txtQty = document.formname.price.value;

$.ajax({
type: "GET",
url: "update.asp",
data: "Price="+txtprice+"&id="+id,
success: function(msg){
$("#ShowPrice").html("<font color="red">Price updated as</font>"+(price)+");
}
},
error: function(msg){
alert( "Error :" + msg);
}
});
}
</script>


4. Now create "update.asp" page in that get the request and update the records and send yes or no message to main page

5.here is complete example.



<html>
<head>
<title> Jquery Example </title>
<script language="javascript" src="js/jquery-1.2.3.js" type="text/javascript" ></script>
<script language="javascript" type="text/javascript" >
function update()
{
txtQty = document.formname.price.value;

$.ajax({
type: "GET",
url: "update.asp",
data: "Price="+txtprice+"&id="+id,
success: function(msg){
$("#ShowPrice").html("<font color="red">Price updated as</font>"+(price)+");
}
},
error: function(msg){
alert( "Error :" + msg);
}
});
}
</script>
</head>
<body>

<b>Update Price </b>
<br>
<form name="formname" >
<select name="Price" id="Price" onchange="update()">
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
</select>
<br />
<input type="text" ID="ShowPrice" value="">
<input type="submit" value="submit">
</form>
</body>
</html>

Monday, July 27, 2009

Localizing SiteMap in Asp.net

In Asp.net 2.0 we have a good feature which is Localizing SiteMap .
the are ways to add the localization to you'r site map when you are using xmlSiteMapProvider

you can do that via Explicitly and Implicitly also .
  • using Explicitly


  • <asp:textBox id="Exp" Value='<%$ Resources: Common, Textgoeshere%>'...> </asp:TextBox>

  • using Implictly

  • <asp:Label ID="Impl" meta:ResourceKey="sometext" ... />

    You can also use Programmatically by calling to page.GetLocalResourceObject(...) or Page.GetGlobalResourceObject.

    and this will control all . The menu and Sitemap can be linked to the SiteMapDataSource. we can also localized sitemapitself like that you can do this

    At first Set the attribute enableLocalization="true" . Now add thje resourceKey Attribute to all the SiteMapNode element that you want to Localize.

    Implicit version of Localization


    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" enableLocalization="true">

    <siteMapNode title="Root" description="Description on Link">

    <siteMapNode url="~/Default.aspx" title="Index" resourceKey="Index" description="Main Page" />

    <siteMapNode url="~/Update.aspx" title="Update Resource" resourceKey="Update" description="Update Record" />

    ...

    </siteMapNode>

    </siteMap>



    You can also add the Explicit Version by adding all the resources like title,Description to the resx file by using ResourceKey Property
    like Index.title and Index.Description.

    now as per the Example of ResourceKey file .



    in this file you can get file name could be a resourceKey + "." + Property of siteMap node. you can update that part with the following explicit expressions way


    <siteMapNode url="~/Update.aspx" title="$Resources: SiteMapResourceFile, UpdatePosting" ...="" />


    in this case Your resource file should be located in App_GlobalResources and that must be call ClassName.culture.resx

    Saturday, July 25, 2009

    garbage collection in C#

    Now programmer need not worry about memory management because garbage collection is one of the Great feature is included in asp.net, java ,j2se and all programming language . which will handle the memory and distroy the objects and all.

    Garbage collector runs when the .Net environment determines that it is required to run. However, you can force the garbage collector to run by calling the GC.Collect() method. there are no guarantees that an unreferenced object will be disposed in the first run of the garbage collector. Objects that do not have a destructor or finalizer get removed in a single pass, whereas objects with destructors need two passes to be disposed. at first it get call the destructor and at the second part it will delete that perticular object.

    The .Net Garbage Collector is optimize for following situation.
    1. Objects that have lived the longest are least likely to be become free.
    2. Objects allocated together are often used together.
    3. Objects that were recently allocated are most likely to be freed.

    for Distroying purpose we have Finalizer Method which works as:

    in C#, the finalizer is a protected method as shown below


    protected void Finalize()
    {
    base.Finalize();
    }



    but Instead of declaring a Finalizer, exposing a Dispose method is considered as good.

    Dispose

    by calling GC.SuppressFinalize() we can dispose memory like

    public void Dispose()
    {
    GC.SuppressFinalize(this);
    }



    but in The Microsoft.NET CLR (Common Language Runtime) requires that all resources be allocated from the managed heap. You never free objects from the managed heap-objects are automatically freed when they are no longer needed by the application.

    Garbage collection in .NET is done using tracing collection and specifically the CLR implements the Mark/Compact collector.

    there are two phases :

    1)Find memory that can be reclaimed.
    2)Move all the live objects to the bottom of the heap, leaving free space at the top.

    at last we can say GC is necessarily slower than manual memory management.Programs with GC are huge and bloated; GC isn't suitable for small programs or systems.

    Friday, July 24, 2009

    File upload using ASP

    while designing web form (like client Registration) we required some upload kind of
    control ,for that here is a best example to do this

    here u can upload (text file , image , pdf , video) and all

    steps

    1. open config.inc file and set the path from where u want to access file

    strFolder = "C:\upload\files"
    2. Specify the file size , 0 will give unlimited file size
    lngFileSize = 10000

    3.if you want to excluded the specify the files to be excluded and must be set to blank ("") if none are to be excluded
    strExcludes = ""

    4. if you want to include file then specify the file extension to be allowed
    strIncludes = ".gif;.jpg;.mp3"


    here is the complete source code of file upload

    Wednesday, July 22, 2009

    Iframes and jQuery - Working with an iframe's parent

    Use iframe and Jquery to open another window in it self .This actually may be more desirable as it is simpler and works in more browsers (Firefox, Internet Explorer, Opera 8.54+ tested)



    $( function() {
    var p = parent;
    $("a").click( function() {
    p.$("#myinput").val("Anchor clicked: " + this.href);
    return false;
    })
    })

    Saturday, July 18, 2009

    disable Back button of a browser?

    Most of time we want to disable the " Browser Back" button due to some security reason or any

    other purpose.

    there are some tech. to do this .

    • You can use the location replace method when changing the location.




    • <script language="JavaScript">
      <!--
      if (document.images)
      location.replace('http://www.xyz.com/login.html');
      else
      location.href = 'login.html';
      //-->
      </script>


      In this case "replaces the current history location with the new location."


    • You can load the new location into another window, and then close the old window:


    • <script langauge="JavaScript">
      <!--
      function newWindow(Nameoffile,windowName)
      {
      msgWindow=window.open(fileName,windowName);
      }
      //-->
      </script>
      <a href="javascript:newWindow('welcome.html','window1')">Open Window</a>


    • open in the next window:



    • <a href="login.aspx" target="_blank">New User Login </a>

      So it will open login page in new window

    • You can open a window without a toolbar and Disable backButton from Keyboard and

      Rightclick



    • <script language="JavaScript">
      <!--
      msgWindow=window.open('Login.aspx','windowName','toolbar=no');
      //-->
      </script>


    • You can add code to the previous page to force the browser to go forwards again:



    • <script language="JavaScript">
      <!--
      javascript:window.history.forward(1);
      //-->
      </script>





    There is no direct way to catch the back button event, so you have to play with javascipt to do so.

    happy coding ........

    Friday, July 17, 2009

    Welcome to Google App Engine for Java!

    Google announced the new features for Google App Engine (GAE), but the most important one is the support for Java. Java Developers can use GAE for their applications with small changes. (may be big changes due to datastore restrictions.


    10.000 developers can have an early access to GAE for Java through this link : http://appengine.google.com/promo/java_runtime

    There are also additional feautures as :

    * App Engine’s early look at Java™ language support includes a Java runtime, integration with the new Google Web Toolkit 1.6, and a Google Plugin for Eclipse
    * The Google Secure Data Connector enables centrally-managed access to on-premise data from Google Apps
    * The database import tool makes it easier to move gigabytes of data into App Engine (and export functionality is coming within the month)
    * Cron support can execute scheduled tasks like report generation and DB clean-up at regular interval.

    This new announcement may lead to change in GIS area, like implementing the GeoServer for GAE or other 3th party GIS tools for GAE

    Google announced the new features for Google App Engine (GAE), but the most important one is the support for Java. Java Developers can use GAE for their applications with small changes. (may be big changes due to datastore restrictions :) )


    10.000 developers can have an early access to GAE for Java through this link :
    http://appengine.google.com/promo/java_runtime


    There are also additional feautures as :



    This new announcement may lead to change in GIS area, like implementing the GeoServer for GAE or other 3th party GIS tools for GAE



    google app engine ,



    Thursday, July 16, 2009

    CSS New look at CSS3

    CSS3 is the new kid in the stylesheet family. It offers exciting new possibilities to create an impact with your designs, allows you to use more diverse style sheets for a variety of occasions and lots more. We created this site because we want to share our experiences of CSS3 with you...

    Watch out Preview Preview

    Check Is your browser compatible? Test Drive

    Module status at Status

    Tuesday, July 7, 2009

    import Mail address book using C#

    import Mail address book like gmail,yahoo using C#

    Check the .NET Address Book API's of those providers:



    Monday, July 6, 2009

    example of Microsoft Silverlight Technology

    first time in India when people can watch Indian union budget online.
    conomic Times of India is going to use
    Microsoft Silverlight Technology to stream live Indian union Budget.

    Watch Live

    Here you can see best example of Microsoft Silverlight Technology.
    you can also get more on
    how to work on SilverLight and how it get implement .