Friday, November 26, 2010

How to bind XML File or XML DataSource to a DataList Control in Asp.Net




Please visit my new Web Site https://coderstechzone.com



DataList control is an important control in Asp.Net applications. Most of the times we need to bind DataList control from a Database using Ado.Net datasource. But sometimes we need to bind XML file as Datasource into a DataList control. Here in this article i will demonstrate how one can bind XML data into a DataList control using the datasource XmlDataSource. The output will be:

Bind XML data into DataList controlo

To do the above example we need to write an XML file like:
<?xml version="1.0" encoding="utf-8" ?>
<Customers>
  <Customer>
    <Name>Shawpnendu Bikash Maloroy</Name>
    <Address>Uttara, Dhaka</Address>
    <City>Dhaka</City>
    <Phone>011789657</Phone>
  </Customer>
  <Customer>
    <Name>Bimolandu Bikash Maloroy</Name>
    <Address>Sonaimuri, Noakhali</Address>
    <City>Noakhali</City>
    <Phone>019789687</Phone>
  </Customer>
  <Customer>
    <Name>Purnendu Bikash Maloroy</Name>
    <Address>FirmGate, Dhaka</Address>
    <City>Dhaka</City>
    <Phone>018788767</Phone>
  </Customer>
  <Customer>
    <Name>Shadesh Chandra Chanda</Name>
    <Address>Maijdee, Noakhali</Address>
    <City>Noakhali</City>
    <Phone>015787597</Phone>
  </Customer>
  <Customer>
    <Name>Sajal Chandra Chanda</Name>
    <Address>Maijdee, Noakhali</Address>
    <City>Noakhali</City>
    <Phone>019734557</Phone>
  </Customer>
</Customers>

Now add an aspx page into your project & modify the HTML markup like below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataList_XML.aspx.cs" Inherits="DataList_XML" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>An Example of Binding XML Datasource into DataList Control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1"> 
        <HeaderTemplate>Customer Name</HeaderTemplate>
        <ItemStyle BackColor="Gray" ForeColor="Yellow" />
        <AlternatingItemStyle BackColor="Silver" />
        <ItemTemplate>
            <%# XPath("Name")%>
        </ItemTemplate>
    </asp:DataList>
    
    <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
        DataFile="Customers.xml" 
        XPath="//Customers/Customer">
    </asp:XmlDataSource>
    
    </div>
    </form>
</body>
</html>

Now run the page. Hope you will get your desired output.

Web Parts Drag & Drop functionality in Asp.net Pages




Please visit my new Web Site https://coderstechzone.com



It’s my first article on Asp.net Web Parts. Basically it’s an introduction article how one can start to learn the high end feature of Asp.net web parts. As you knew that most of the portal contains several block. In general the end user can not change the page block orientation or positioning which is termed as personalization. The Asp.net Web Parts gives us the personalization facility with little code. That’s why the Web Parts is necessary to learn. In my below example I will show you how developers can provide the Drag & Drop facility to personalize end user UI.

To do that you have to understand only two things. The first one is WebPartManager & the second one is WebPartZone.

WebPartManager:
This Asp.net server control manages the state of the zones per user basis. The most important part is you must place an Asp.net WebPartManager server control in each page. But the situation is different for master page as we know. The another importance of the WebPartManager server control is to maintain the communication between different elements contained in a zone or within different zone. Let’s say in one zone you display the product list & in another zone you display the product details. Which means zones are dependent on each other. If you select a product in first zone then you must change the product details in next zone. For such type of cases communication is required done by WebPartManager.

WebPartZone:
WebPartZone contains the elements that you want to Drag & Drop. You can Drag & Drop contains from one zone to another zone. The WebPartManager just controls the zones. You cannot put zone contents into the rest of the pages which does not contain another zone.

Note:
Please note that by default Asp.net creates ASPNETDB.MDF and stores it in the App_Data folder.

Start Example:
Add an Aspx page in your project. Write the below HTML markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebParts.aspx.cs" Inherits="WebParts" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>An Example on Asp Web Parts</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:WebPartManager ID="WebPartManager1" runat="server" >
        </asp:WebPartManager>
        <table border="1">
        <tr style="background:Blue">
        <td colspan="3">
        <h1 style="color:White">Welcome to shawpnendu.blogspot.com</h1> 
        </td>
        </tr>
        
        <tr>
        <td>
        <asp:WebPartZone ID="WebPartZone1" runat="server" HeaderText="Enter Name">
            <ZoneTemplate>
            <asp:TextBox runat="server" ID="txtLastName" Title="Enter Last Name:"></asp:TextBox>
            </ZoneTemplate>
        </asp:WebPartZone>
        </td>
        
        <td>
        <asp:WebPartZone ID="WebPartZone2" runat="server" HeaderText="Enter Name">
            <ZoneTemplate>
            <asp:TextBox runat="server" ID="txtMiddleName" Title="Enter Middle Name:"></asp:TextBox>
            </ZoneTemplate>
            </asp:WebPartZone>
        </td>
        
        <td>
        <asp:WebPartZone ID="WebPartZone3" runat="server" HeaderText="Enter Name">
            <ZoneTemplate>
            <asp:TextBox runat="server" ID="txtFirstName" Title="Enter First Name:"></asp:TextBox>
            </ZoneTemplate>

        </asp:WebPartZone> 
        </td>
        
        </tr>
        </table>
    </div>
    </form>
</body>
</html>

Please note that control Title property will represent the section name of a zone.

Now run the page & you will get the below output:
Asp.Net Web Parts Introduction

In this scenario you will not get the Drag & Drop facility. Only get Minimize & close option in each zone. Because the Drag & Drop facility based on WebPartManager DisplayMode property. The default value is "Browse". If you change the mode from "Browse" to "Design" mode then you will get Drag & Drop Facility like below:

Asp.Net Web Parts Drag & Drop

To change the WebPartManager DisplayMode property just write the below code:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WebPartManager1.DisplayMode = WebPartManager1.SupportedDisplayModes[1];
            Response.Write("Current MODE= " + WebPartManager1.SupportedDisplayModes[1].Name + "");
        }
    }

Ok now test the page & start to learn Asp.Net Web Parts. Drag one content & Drop the selected content into another zone. Now run the page again & the interesting thing is the page retain your last zone orientations. Because Asp.net stores your action into the ASPNETDB.MDF. Later on i will discuss zone to zone communication steps.

Saturday, November 13, 2010

How to Install Firebug Add-on in your Mozilla Firefox Browser




Please visit my new Web Site https://coderstechzone.com



The web developers most important tool is Firebug. It's basically a Mozilla Firefox add-on which makes our I mean developers life is very ease to debug and develop web pages. To inspect HTML or ASPX page elements even javascript one can easily use the firebug add-on. The firebug application provide us to detect bugs on any website. It can identify any tag mistakes or CSS conflicts that you have made in your page incorrectly. Firebug also has a live modification feature where you can change the code & see the effect immediately.

To install Firebug in your Mozilla Firefox follow the below steps:

1. Open Firefox Browser and click into the Tools Menu. Then select Add-ons.
Firefox_tools Menu

2. Now a popup window will open. Click on Browse All Add-ons at the right side of the popup window.
Firefox_browse_Add-ons

3. Now a new tab will appear with a search box. Write Firebug and click on continue button.
firebug search

4. Now select the Firebug Add-on from the list and click on “Add to FireFox button”.
pre installation of firebug

5. A new popup window will open. Click on Install Now button.
Installation of firebug

6. That's it. You have successfully installed firebug add-on in your Mozilla Firefox browser.

To ensure the installation of firebug add-on please restart the FireFox. Now you will find a logo in the bottom left or bottom right corner of your browser. To test the firebug load the page where you stuck and click on the logo to continue your inspection.

Hope now you will be ready to use the firebug application and start detecting those bugs that are stopping your design from showing the way you want it.

Wednesday, November 3, 2010

How to use optional parameter in SQL server SP




Please visit my new Web Site https://coderstechzone.com



When you are going to write a generic SP for any business purpose you may realize the necessity of optional parameter. Yes Sql server gives us the opportunity to use optional parameter in SP arguments. You may write a SP with 3 arguments but based on your business rule you may pass one or two or three valuse as you want. This policy not only ease our life but also help us to write short SP. Here in this article i will discuss how one can create a optional list SP & execute thie SP or stored procedure.










Ok first write a SP with two optional field like below:
ALTER procedure Optional_Procedur 
@Name varchar(200)=null,
@Age int=null
As
BEGIN
if @Name is not null  
 print 'Your Name Is '+@Name
if @Age is not null
 print 'Your Age '+Convert(varchar(3),@Age)
END

Now you can call the SP in many different ways like:
exec Optional_Procedur 'Shawpnendu'
print '-----------------------------'
exec Optional_Procedur 'Shawpnendu',32
print '-----------------------------'
exec Optional_Procedur @Name='Shawpnendu'
print '-----------------------------'
exec Optional_Procedur @Age=32


The query output is given below:

Your Name Is Shawpnendu
-----------------------------
Your Name Is Shawpnendu
Your Age 32
-----------------------------
Your Name Is Shawpnendu
-----------------------------
Your Age 32

I.E. You can send parameter specific values or sequential values or you are not bound to send parameter values in this regard.

Monday, November 1, 2010

Error: 'object could not be found' or 'invalid object name'?




Please visit my new Web Site https://coderstechzone.com



As a Developer i thought you may experience one of two errors frequently, even though you thought the object already exist. The error like below:

Msg 208, Level 16, State 1, Line 1
Invalid object name 'Table/View Name'.

OR

Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure ''.






Solution:
To Avoid Such type of error keep in mind always the following considerations:

1. The connecting user does not have SELECT, UPDATE, INSERT, DELETE, EXEC permissions on that object/objects.

2. your are logging/connecting as a different user that you have expected.

3. Referencing the object without an owner name prefix may raise this error;

4. your connected database is wrong;

5. May be you have written wrong object name or spelled incorrectly.

How to determine whether a table is exist or not in Sql Server database




Please visit my new Web Site https://coderstechzone.com



In some cases we need to identify whether a table is exist or not in a sql server database. This is very simple & now i am sharing with you. Hope it will works like a handbook for you.













Query:
IF EXISTS (SELECT 1 
    FROM INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_TYPE='BASE TABLE' 
    AND TABLE_NAME='tablename') 
        SELECT 'table exists.' 
ELSE 
        SELECT 'table does not exist.'

Hope it will help you.
Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash