Today Topic is Fill The Grid Using XML and XSLT
I have taken help from my Senior.
1> You Need To Create XML File.
2> You Need to Create XSLT it Mean schema File Using XSLT.
3> After that take the XML Control in Your .aspx Page.
this is the process to achieve the desire result.
if you are facing any Problem please send me a message i am trying to solve that problem
My XML File Name Is Text.XML
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" herf="TestDemo.xsl"?>
<Test>
<Tests>
<name>C++</name>
<cost>2000</cost>
</Tests>
<Tests>
<name>DotNet</name>
<cost>10000</cost>
</Tests>
</Test>
My XLST File Name Is Tests.Xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="/">
<table border="1">
<tr>
<th>Name</th>
<th>Price</th>
</tr>
<xsl:for-each select="Test/Tests">
<tr>
<td>
<br>
<xsl:value-of select="name"/>
</br>
</td>
<td>
<br>
<xsl:value-of select="cost"/>
</br>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
My .aspx page name is Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:gridview ID="Gridview1" runat="server"
AutoGenerateColumns="True"
>
</asp:gridview>
<asp:Xml ID="Xml1" runat="server"></asp:Xml>
</div>
</form>
</body>
</html>
And last but not the list My .CS File name is Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Xml.Xsl;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
XmlDocument docXML = new XmlDocument();
docXML.Load(Server.MapPath("Test.xml"));
XslTransform docXSL = new XslTransform();
docXSL.Load(Server.MapPath("Tests.xslt"));
Xml1.Document = docXML;
Xml1.Transform = docXSL;
DataSet DataSet;
string filePath = Server.MapPath("Test.xml");
DataSet = new DataSet();
//Read the contents of the XML file into the DataSet
DataSet.ReadXml(filePath);
Gridview1.DataSource = DataSet.Tables[0].DefaultView;
Gridview1.DataBind();
}
}
}
This is The Solution
Cheers
Bindas....
Friday, August 20, 2010
Tuesday, August 17, 2010
How To Bind The Grid Dynamically In Wpf
Window Presentation Foundation How To Bind The Grid Dynamically In Wpf. I want to Express My Thought Through Coding Please Understand. if you have any dought please Send Me Your Query. This is Simple Example I have taken one List Box and Fireing One Event on Window Load Event.
First Of All You Need To Create The Database, In This Sample Application I am Using Sql Server. My Database Name is Test That Contain table and table Contain Some Attribute Name Is EmpId, Ename, Address and My Table Name is tblEmp. So, Viewer you need to do This part i am unable to upload my sample application
After That This Couple Of Line You write in Window1.XAML
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="280" Width="563" Loaded="Window_Loaded">
<Window.Resources>
<DataTemplate x:Key="listBoxTemplate">
<StackPanel Margin="4">
<DockPanel >
<TextBlock FontWeight="Bold" Text="EmpIdentification:"
DockPanel.Dock="Right"
Margin="5,0,10,0"/>
<TextBlock Text=" " />
<TextBlock Text="{Binding EId}" Foreground="Green" FontWeight="Bold" />
</DockPanel>
<DockPanel >
<TextBlock FontWeight="Bold" Text="Name:" Foreground ="DarkOrange"
DockPanel.Dock="Left"
Margin="5,0,5,0"/>
<TextBlock Text="{Binding Ename}" />
</DockPanel>
<DockPanel>
<TextBlock FontWeight="Bold" Text="Address" Foreground="RoyalBlue"
DockPanel.Dock="Left"
Margin="5,0,15,0"/>
<TextBlock Text="{Binding Address}"/>
</DockPanel>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid Margin="49,12,29,0" Name="grid1" Height="221" VerticalAlignment="Top" Width="467">
<ListBox Margin="17,8,15,26" Name="lstnox1" ItemsSource="{Binding Tables[0]}"
ItemTemplate="{StaticResource listBoxTemplate}" />
</Grid>
</Window>
And after That You Need To Open Your Window1.XAML.CS and put These Couple Of Lines
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public SqlConnection connection;
public SqlCommand command;
string sql = "SELECT EmpId,Ename,Address FROM tblEmp";
string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Test.mdf;Integrated Security=True;User Instance=True";
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
BindGrid();
}
private void BindGrid()
{
DataSet dtSet = new DataSet();
using (connection = new SqlConnection(connectionString))
{
command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter();
connection.Open();
adapter.SelectCommand = command;
adapter.Fill(dtSet, "tblEmp");
lstnox1.DataContext = dtSet;
}
}
}
}
This is Code For Dynamically You Can Bind The Grid In WPF And You Out Put Look Like
Cheers
Bindas.....
First Of All You Need To Create The Database, In This Sample Application I am Using Sql Server. My Database Name is Test That Contain table and table Contain Some Attribute Name Is EmpId, Ename, Address and My Table Name is tblEmp. So, Viewer you need to do This part i am unable to upload my sample application
After That This Couple Of Line You write in Window1.XAML
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="280" Width="563" Loaded="Window_Loaded">
<Window.Resources>
<DataTemplate x:Key="listBoxTemplate">
<StackPanel Margin="4">
<DockPanel >
<TextBlock FontWeight="Bold" Text="EmpIdentification:"
DockPanel.Dock="Right"
Margin="5,0,10,0"/>
<TextBlock Text=" " />
<TextBlock Text="{Binding EId}" Foreground="Green" FontWeight="Bold" />
</DockPanel>
<DockPanel >
<TextBlock FontWeight="Bold" Text="Name:" Foreground ="DarkOrange"
DockPanel.Dock="Left"
Margin="5,0,5,0"/>
<TextBlock Text="{Binding Ename}" />
</DockPanel>
<DockPanel>
<TextBlock FontWeight="Bold" Text="Address" Foreground="RoyalBlue"
DockPanel.Dock="Left"
Margin="5,0,15,0"/>
<TextBlock Text="{Binding Address}"/>
</DockPanel>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid Margin="49,12,29,0" Name="grid1" Height="221" VerticalAlignment="Top" Width="467">
<ListBox Margin="17,8,15,26" Name="lstnox1" ItemsSource="{Binding Tables[0]}"
ItemTemplate="{StaticResource listBoxTemplate}" />
</Grid>
</Window>
And after That You Need To Open Your Window1.XAML.CS and put These Couple Of Lines
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public SqlConnection connection;
public SqlCommand command;
string sql = "SELECT EmpId,Ename,Address FROM tblEmp";
string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Test.mdf;Integrated Security=True;User Instance=True";
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
BindGrid();
}
private void BindGrid()
{
DataSet dtSet = new DataSet();
using (connection = new SqlConnection(connectionString))
{
command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter();
connection.Open();
adapter.SelectCommand = command;
adapter.Fill(dtSet, "tblEmp");
lstnox1.DataContext = dtSet;
}
}
}
}
This is Code For Dynamically You Can Bind The Grid In WPF And You Out Put Look Like
Cheers
Bindas.....
Sunday, August 15, 2010
What is Mvc Design Pattern
Hi, All
This is My Second Blogs, if you Know about The three tire architecture then MVC is very easy
to understand becoz it follow three tire architechture rule. first of all
What is MVC Design Pattern ?
MVC (Model View Controller) pattern is very useful for Web
based e-commerce application.
Asp.Net web application
aspx, ascx, master pages are View
aspx.cs, ascx.cs, master.cs are Controller
App_Code folder contains classes and some references –
Model Component
The Model holds the data displayed by the View and managed by the
Controller. The View is responsible for delivering output to the End User,
and the Controller reacts to End User actions and updates the Model
appropriately
But I want to Tell You About Model, You Very Careful about this Layer.
Model
This layer has all our business logic. This is the most important layer. This layer will have our core functionality. This layer should be designed in such a way that out core and complex logic should be designed as functions and these function should be marked as overridable so that the inheriting classes can re-use the logic or override the logic. We should not make all the functions in the layer as overridable this may raise some security Issue.
MVC Advantages: Business logic can be easily modified
without affecting or any need to make changes in UI.
This is the Meaning of MVC Design pattern. but if you relate with Three tire architechture.
then first we define the Business Layer, Data Access Layer and last but not the list Presentation layer.
same thing here also aspx page represent Presentation Layer. Business layer it is a class library, In that case you need write
The logic how you can connect with the data access layer and presentation layer, data access layer you are connect with database and business Logic layer.
MVC Nothing But a successful development and reuse of code
Cheers
Bindas.........
This is My Second Blogs, if you Know about The three tire architecture then MVC is very easy
to understand becoz it follow three tire architechture rule. first of all
What is MVC Design Pattern ?
MVC (Model View Controller) pattern is very useful for Web
based e-commerce application.
Asp.Net web application
aspx, ascx, master pages are View
aspx.cs, ascx.cs, master.cs are Controller
App_Code folder contains classes and some references –
Model Component
The Model holds the data displayed by the View and managed by the
Controller. The View is responsible for delivering output to the End User,
and the Controller reacts to End User actions and updates the Model
appropriately
But I want to Tell You About Model, You Very Careful about this Layer.
Model
This layer has all our business logic. This is the most important layer. This layer will have our core functionality. This layer should be designed in such a way that out core and complex logic should be designed as functions and these function should be marked as overridable so that the inheriting classes can re-use the logic or override the logic. We should not make all the functions in the layer as overridable this may raise some security Issue.
MVC Advantages: Business logic can be easily modified
without affecting or any need to make changes in UI.
This is the Meaning of MVC Design pattern. but if you relate with Three tire architechture.
then first we define the Business Layer, Data Access Layer and last but not the list Presentation layer.
same thing here also aspx page represent Presentation Layer. Business layer it is a class library, In that case you need write
The logic how you can connect with the data access layer and presentation layer, data access layer you are connect with database and business Logic layer.
MVC Nothing But a successful development and reuse of code
Cheers
Bindas.........
Friday, August 13, 2010
SomeThing
This is Ajit Singh, I am a Software Engg.. This is My First Blog. I decide Today i need to write the Blogs and After That I Have Start Writing Blogs. This is Good Things wright.
I want To Tell To Something To U All.
Work hard and raise yourself to a level where, before penning your destiny,
God himself will ask "tell me,
what do you want your destiny to be!"
But In This is Morden Era U Need to Change Your Self
In Place Work hard U are need to put Smart Work. This is The Definition Of Success...
Cheers
Always Bindassssssssssss............................................
I want To Tell To Something To U All.
Work hard and raise yourself to a level where, before penning your destiny,
God himself will ask "tell me,
what do you want your destiny to be!"
But In This is Morden Era U Need to Change Your Self
In Place Work hard U are need to put Smart Work. This is The Definition Of Success...
Cheers
Always Bindassssssssssss............................................
Subscribe to:
Posts (Atom)