Anirudh’s Weblog


SILVERLIGHT DYNAMIC DATAGRID
September 2, 2011, 9:23 am
Filed under: Silverlight | Tags: ,

This post is the demo for displaying data from WCF in datagrid in silverlight 4. I have used Department data for demo. Please follow points below:

1. Create a class named DepartmentClass.cs (WCF part)
public class DepartmentClass {
public string DepartmentName { get; set; }
public string Description { get; set; }
}
2. Write a select query in .svc.cs file as per below method, we need to define this methid in interface also. The below method is to show how we will send the values to silverlight from WCF. Instead of ObservableCollection we can take list also. da = DataAdapter and con = SqlConnection (WCF part)

public ObservableCollection SelectDepartment(DepartmentClass objDept){
da.SelectCommand = new SqlCommand(“SELECT departmentName, description FROM tblDepartment WHERE isActive=’true’”);
da.SelectCommand.Connection = con;
using (var deptData = da.SelectCommand.ExecuteReader()){
while (deptData.Read()){
_departmentClasses.Add(new DepartmentClass(){
DepartmentName = deptData.GetString(1),
Description = deptData.GetString(2)});
}
}
con.Close();
return _departmentClasses;
}

3. Write following code in .xaml file. In binding we will provide variable name used in Class. (silverlight part)

  <sdk:DataGrid AutoGenerateColumns="False" Grid.Row="6"
            Height="187" HorizontalAlignment="Left"
            Margin="116,13,0,0" Name="dataGrid1"
            VerticalAlignment="Top" Width="433">
   <sdk:DataGrid.Columns>
    <sdk:DataGridTextColumn Width="150" Header="Name"
                  Binding="{Binding DepartmentName}" />
     <sdk:DataGridTextColumn Width="280" Header="Description"
               Binding="{Binding Description}" />
   </sdk:DataGrid.Columns>
  </sdk:DataGrid>

4. Following code will be written in .xaml.cs file in constructor.(silverlight part)

public Department()
{
InitializeComponent();

var depProxy = new AdminServiceReference.IadminClient();
depProxy.SelectDepartmentCompleted +=new EventHandler(depProxy_SelectDepartmentCompleted);
depProxy.SelectDepartmentAsync();
}

private void depProxy_SelectDepartmentCompleted(object sender, SelectDepartmentCompletedEventArgs e)
{
if (e.Result != null)
{
dataGrid1.ItemsSource = e.Result;
}
}



Storing XML file’s data in SQL through Store Procedure
April 19, 2010, 11:47 am
Filed under: ASP.NET, SQL, XML | Tags: , , ,

CREATE PROCEDURE [dbo].[Student]
– Add the parameters for the stored procedure here
@studentlXML XML
AS
BEGIN
– SET NOCOUNT ON added to prevent extra result sets from
– interfering with SELECT statements.
SET NOCOUNT ON;

— Insert statements for procedure here
Declare @CountHandler int
Exec SP_XML_PrepareDocument @CountHandler OUTPUT,@studentlXML
INSERT INTO tblStudent –Table name where we have to save xml data
SELECT * FROM OPENXML(@CountHandler,”/friends/friend”,2)
WITH tblStudent
Exec SP_XML_RemoveDocument @CountHandler
END
END

NOTE: @studentlXML is a xml file can be passed as a string or file
friends is the parent node of xml and friend is a node under friends node, which will be excluded and rest nodes will be treated as column. Please note that node name should be exactly same as column name in table tblStudent



Filling Drop Down List From XML File in ASP.NET C#
April 19, 2010, 11:33 am
Filed under: ASP.NET, XML | Tags: , , , ,

If XML is saved as Employees.xml in C Drive:-

Code to be written on PAGE LOAD

DataSet ds = new DataSet();
ds.ReadXml(MapPath(“C:\\Employees.xml”));

DataView dv = ds.Tables["Employee"].DefaultView;

dv.Sort = “Name”;

ddlCountry.DataTextField = “Name”;
ddlCountry.DataValueField = “ID”;

ddlCountry.DataSource = dv;
ddlCountry.DataBind();



Date Format Style
April 19, 2010, 11:23 am
Filed under: Uncategorized | Tags: ,

Format Style Output
MM-dd-yyyy : 04-09-2010
MMM dd, yyyy : Apr 09, 2010
ddd MM, yyyy : Fri 04, 2010
dddd MM, yyyy : Friday 04, 2010
MMM ddd dd, yyyy : Apr Fri 09, 2010
MMMM ddd dd, yyyy : April Fri 09, 2010
MMMM dddd dd, yyyy : April Friday 09, 2010



Using IFormatProvider for DateTime Formats in ASP.NET C#
April 19, 2010, 11:20 am
Filed under: Uncategorized

string myDateTime;
myDateTime= “19/02/2008 05:44:00″;
IFormatProvider myculture = new CultureInfo(“fr-Fr”, true);
dt = DateTime.ParseExact(myDateTime, “dd/MM/yyyy hh:mm:ss”, myculture, DateTimeStyles.NoCurrentDateDefault);



Get Current Page URL IN ASP.NET 2
February 5, 2009, 2:27 pm
Filed under: ASP.NET | Tags: , , ,

Following line will return complete url of the current page in asp.net 2.0

Request.Url.AbsoluteUri



DATE and TIME in SQL
February 4, 2009, 2:16 pm
Filed under: SQL | Tags: , , , , , , , ,

please check the following link for any type of date and time problem:-

http://www.codeproject.com/KB/showcase/RedGate_DateTime.aspx



Filling Dropdown List from XMLHTTP response
December 24, 2008, 7:28 am
Filed under: Ajax
Following function is to fill dropdownlist (TEXT and VALUE) from the response we get from handler file. Just pass dropdown ID and the string in this function. 
function FN_fillList(ddl,str){
        var arr = str.split(“;”);
        //To Remove All Items of Drop Down
        document.getElementById(ddl).length = 0;
        document.getElementById(ddl).options[0] = new Option(‘Select’,0);
        //To Add Items In Drop Down
        for(var i=1,j=1; i < arr.length;i=i+2,j++){
            document.getEle mentById(ddl).options[j] = new Option(arr[i],arr[i+1]);
        }
    }


usefull link for saving image in database
December 6, 2008, 11:31 am
Filed under: Uncategorized

http://aspguy.wordpress.com/2008/10/17/reading-and-writing-images-fromto-database/

http://www.codeproject.com/KB/database/ImageSaveInDataBase.aspx

http://www.beansoftware.com/asp.net-tutorials/images-database.aspx



Getting Control ID in Javascript
November 12, 2008, 11:23 am
Filed under: JavaScript | Tags: , , , ,

There are two ways of getting the id of dotnet control in javascript 

First

document.getElementById(“ctl00$ContentPlaceHolder$TextBox1″)

SECOND

document.getElementById(“<%=TextBox1.ClientID %>”)

If you want to get the id of html control then just write control id in double quotes.For example:-

document.getElementById(“TextBox1″)




Follow

Get every new post delivered to your Inbox.