Exceptions while Configuring WCF on Windows 7

Hello All,

Recently I have installed Windows 7 on my machine and was trying to configure all my existing projects. While configuring my Service Project on IIS, I was getting some exceptions. Finally I could manage to configure it. If you are getting exception which says:

HTTP Error 404.3 - Not Found.

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Or

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

To resolve this you just need to run “%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe -i”
 This will create svc mapping.

Also if anyone is getting Forbidden exceptions, like this:

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.

Go to IIS, select the Virtual Directory on the left side. Once you select the Virtual directory on right side of that window you will find an option of Directory Browsing. Double click on it and check whether it’s enabled or disable in the Actions List. Click on enable in Action List.

I didn’t not check it on Vista but if you are getting same exceptions then you could try with the same settings. Hope it will work on Vista also.


Please leave your comments to help me improve my blog.

Thank You for visiting the Blog. Happy Coding! :)

Lock wait timeout exceeded; try restarting transaction in MySQL

Today while I was trying to clean up the MySQL Database, I got the following error:
Error Code : 1205
Lock wait timeout exceeded; try restarting transaction
(0 ms taken)

I was surprise to see this error as the same query was working fine before few minutes and then what happen all of sudden. The error came because of some other guy was trying to delete records simultaneously without my knowledge and so the transaction got locked. After doing some Google search I could figure out the solution for it.

Here is what you have to do:

Just run “SHOW INNODB STATUS” in your query browser you will get the status of INNODB which contains LIST OF TRANSACTIONS FOR EACH SESSION. In that just find all the Active thread id’s, say you find one thread id = 148 and then just select and kill that thread id, like this: KILL 148.


That’s all you have to do.

Hope that helps.


Please leave your comments to help me improve my blog.
 
Thank You for visiting the Blog. Happy Coding! :)

How to find Max/Min ID in DataTable

These days I'm working on both ASP.NET and Silvelight. Though I'm working on ASP.NET after a year now, thought posting some of the articles on ASP.NET which I had in my mind but couldnt devote much time. Here is one of them.
How to find the Max/Min ID in DataTable. DataTable has Select Method by which you can get the related records as you do it in SQL or for any database. I'm creating an Employee DataTable which has EmployeeID, FirstName and Lastname columns and fill that with some dummy data.


DataTable objDT = new DataTable();
DataColumn objDC = new DataColumn("EmployeeID", System.Type.GetType("System.Int32"));
objDT.Columns.Add(objDC);
objDC = new DataColumn("FirstName", System.Type.GetType("System.String"));objDT.Columns.Add(objDC);
objDC = new DataColumn("LastName", System.Type.GetType("System.String"));

objDT.Columns.Add(objDC);

DataRow objDR = objDT.NewRow();
objDR["EmployeeID"] = 1;
objDR["FirstName"] = "Lalit";
objDR["LastName"] = "Sharma";
objDT.Rows.Add(objDR);

 
objDR = objDT.NewRow();
objDR["EmployeeID"] = 2;
objDR["FirstName"] = "Aditi";
objDR["LastName"] = "Deodhar";
objDT.Rows.Add(objDR);

objDR = objDT.NewRow();
objDR["EmployeeID"] = 3;
objDR["FirstName"] = "Nimish";
objDR["LastName"] = "Navadkar";
objDT.Rows.Add(objDR);

objDR = objDT.NewRow();
objDR["EmployeeID"] = 4;
objDR["FirstName"] = "Pragati";
objDR["LastName"] = "Dukale";
objDT.Rows.Add(objDR);

objDR = objDT.NewRow();
objDR["EmployeeID"] = 5;
objDR["FirstName"] = "Rumpa";
objDR["LastName"] = "Gune";
objDT.Rows.Add(objDR);

objDR = objDT.NewRow();
objDR["EmployeeID"] = 6;
objDR["FirstName"] = "Abhijit";
objDR["LastName"] = "Parkhi";
objDT.Rows.Add(objDR);

//This is the select query for Max
string selectCommand = "Max(EmployeeID)";

//returns the Max EmploeeID
int nextID = Convert.ToInt32((object)objDT.Compute(selectCommand, string.Empty));
Likewise we can find Min ID in DataTable.
 
Hope that helps.
 
Please leave your comments to help me improve my blog.

Thankyou for visiting the Blog. Happy Coding! :)

How to find DataTable Row Number without ID column.

Hello All,

In ASP.NET one of my favourite topic is playing with DataSet and DataTable. Today one of my colleague asked me "how to find row number of DataTable if we dont have ID column".

Here is a simple way to do it:

int iRowNumber = objDT.Rows.IndexOf(objDT.Select("Name = Varsha")[0]);

iRowNumber will have Row number.

Hope that helps.

Please leave your comments to help me improve my blog.

Thank You for visiting the Blog. Happy Coding! :)

Query to MySQL from C# returns System.Byte[]

Hello All,

I'm working on Mysql for almost a year now but yesterday I got one issue which was killing me. I wrote a Stored Procedure in MySQL and execute it in MySQL Browser and it execute very well but when I execute the same Stored Procedure in asp.net and bind the returned DataSet with GridView, it always shows System.Byte[] in the Title Column.

The problem was that the columns which I had selected in that query was having DataType as LongText and LONGTEXT type is a kind of BLOB type (set of byte), so it was returning System.Byte[].

I checked it on google, tried different ways to fix it but nothing helped me and finally I thought firing a query on it and it worked. Something like this:

SELECT
           ID
           ,TitleName
FROM (

                   SELECT
                                  ID
                                  ,REPLACE(Title, "$", "'") AS TitleName
                   FROM
                                  tbEmployee
         ) A

This it what I did and its working fine.

Hope this helps you all.

Happy Coding :)

Whitespace is not allowed after end of Markup Extension -- Silverlight Compile Time Error

Today while working on one of my Silverlight Project, I did some changes in the user control and built the Project and all of sudden I got the compile time error saying:
Whitespace is not allowed after end of Markup Extension.

I tried finding where exactly the whitespace has come. Initially I thought while giving name to any of control I gave white space in it but was wrong and then I could find what was the issue. Check the image you will understand what mistake I did and I thought of writting this blog.

Happy Coding!!!!

How to Align Text in DataGrid Cell in Xaml and in Code Behind

Hello,

While answering a query on silverlight forum, I thought of writing this article.
Quoting the question as:

DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Result";
textColumn.Binding = new Binding("Result");
dataGrid1.Columns.Add(textColumn);

how i can set RESULT alignment right?

Here is what you have to do, I will show you this in both ways like doing it in Xaml Page and doing it in code behind.

First add the Style in your User Control Resource:

<UserControl.Resources>
      <Style x:Key="AlignRight" TargetType="Data:DataGridCell">
          <Setter Property="HorizontalContentAlignment" Value="Right" />
     </Style>
</UserControl.Resources>
 
I'm doing this for Right Align but you can change it according to your requirement.
 
Next, how to do this in Xaml Page? Its very simple, apply this style to whichever column you want, like this:
 
<Data:DataGridTextColumn Header="Amount" Width="90" Binding="{Binding Amount}" IsReadOnly="True" CellStyle="{StaticResource AlignRight}"></Data:DataGridTextColumn>
 
Now how to do this in code behind:
 
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Result";
textColumn.Binding = new Binding("Result");
textColumn.CellStyle = Resources["AlignRight"] as Style;
dataGrid1.Columns.Add(textColumn);

Comments are always welcome.

Happy Coding :)

ComboBox inside Silverlight DataGrid

Hello All,

How to implement ComboBox inside Silverlight DataGrid. Here I have uploaded a sample Project which would help you all.

Source Code

Happy Coding :)

How to Bind Silverlight ComboBox with Enum

Hello All,

Binding Silverlight ComboBox with Enum. Suppose we have Enum like this:

public enum Schedule
{
     Day = 1,
     Week = 7,
     Month = 30,
     Year = 365
}
 
then how are we going to bind it with ComboBox. Here is the code:

// Returns all the Enums

public static T[] GetEnumValues()
{
       var type = typeof(T);
       if (!type.IsEnum)
       throw new ArgumentException("Type '" + type.Name + "' is not an enum");
       return (from field in type.GetFields()
       where field.IsLiteral
       select (T)field.GetValue(type)).ToArray();
}
 
ComboBox cbo = sender as ComboBox;
var enums = GetEnumValues();
cbo.ItemsSource = enums;

Happy Coding :)

How to find the last identity value inserted in MYSQL

Hello All,


If you are writing an Insert query and what to find out the last inserted ID then here is what you execute to get the last inserted ID.

DECLARE iID INT;
-- Your Insert query goes here and iID will have your last Inserted ID.
SELECT LAST_INSERT_ID() INTO iID;

Hope that helps.

Bullets For Silverlight ListBox

Here is what the output looks like:












While answering a query on silverlight forum, I thought of writing this blog.

Quoting the question as:
How do I add Bullet Points in SilverLight 4.0?
I tried the <ul> </ul> HTML code and it doesn't work. Is there a special code in SilverLight for Bullet Points?

Here is what you can try:

Xaml Code:

<ListBox x:Name="lbMyBullet" VerticalAlignment="Stretch" Margin="5,2,2,2" Height="150" HorizontalAlignment="Stretch" Width="240">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="images/small-arrowblue.png" VerticalAlignment="Center" Height="9" Width="7"></Image>
<TextBlock x:Name="myBulletText" Margin="5,2,0,0" VerticalAlignment="Top" Text="{Binding Path=Name}" ToolTipService.ToolTip="{Binding Path=Name}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

In Code Behind:
 
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
}

ObservableCollection employee = new ObservableCollection();
employee.Add(new Employee() { ID = 1, Name = "Nimish"});
employee.Add(new Employee() { ID = 2, Name = "Vikas"});
employee.Add(new Employee() { ID = 3, Name = "Pooja"});
employee.Add(new Employee() { ID = 4, Name = "Maya"});
employee.Add(new Employee() { ID = 5, Name = "Kiran"});
employee.Add(new Employee() { ID = 6, Name = "Pragati"});
employee.Add(new Employee() { ID = 7, Name = "Lalit"});
employee.Add(new Employee() { ID = 8, Name = "Neha"});
employee.Add(new Employee() { ID = 9, Name = "Sachin"});
employee.Add(new Employee() { ID = 10, Name = "Ishita"});

lbMyBullet.ItemsSource = employee;

You have to just change the image path.

Happy coding :)

Get the Monday date of a given week in a given year

A user on Silverlight forum made me to write this post.

Quoting the user question:
"I want to get first and last date of week given by a week number and year"

For example if Week Number is 26 and Year is 2009, then the output must be 29/06/2009.

However I did the first date of given week and year, here is what the logic is:

1) Get the date of the first day of the given year. That is the first date of any year would be Year + "-1-1".
2) Find out the date of the monday of this week. For example, for 2009, the first monday date would be 12-29-2008.
3) Now, when we add (number of weeks * 7) to the very first monday, we get the monday of the given week and given year.

Thats all we have to do.

Here is the sample code:

int iWeek = 26;
int iYear = 2009;
DateTime firstDayOfYear;
DateTime firstMondayOfYear;
DateTime finalDate;
//Step 1
firstDayOfYear = Convert.ToDateTime(iYear.ToString() + "-1-1");
DayOfWeek t = 1 - firstDayOfYear.DayOfWeek + 1;
int intDayOfWeek = (int)firstDayOfYear.DayOfWeek;
//Step 2
firstMondayOfYear = firstDayOfYear.AddDays(1 - intDayOfWeek).Date;
//Stpe 3
finalDate = firstMondayOfYear.AddDays((iWeek) * 7);
 
finalDate will have 6/29/2009.
 
Happy coding  :)

How to write Maths Equation In Silverlight

Hello All,

Inspite of being a PG in Mathematics I always use to think how should we write a maths equation in Silverlight or say superscript for a texblock, So I thought I should blog for it.

Suppose if we want to write an equation something like this:

then how are we going to write this in Silverlight.
Here is a simple way:

I have take a TextBlock in my Xaml Page named tbMathsEquation.
In Code Behind: 
tbMathsEquation.Text  = "(x + 1)";
tbMathsEquation.Text += String.Format(" {0,-3}", '\u00B2');
tbMathsEquation.Text += " = ";
tbMathsEquation.Text += "x";
tbMathsEquation.Text += String.Format(" {0,-3}", '\u00B2');
tbMathsEquation.Text += " + ";
tbMathsEquation.Text += "2x + 1";
 
Here I'm using Unicode Character which might be categorized as an uppercase letter, a lowercase letter, a decimal digit number, a letter number, a connector punctuation, a math symbol, or a currency symbol.
 
Thats all we have to do.
 
Happy Coding :)

Swapping Elements frm one ListBox to another using JavaScript.

Hello All,

Swapping elements from one listbox to another in ASP.NET we always have to postback the page but using Javascript you can do this without doing postback for that page.

You can down the Source Code.

Happy Coding :)

जो बीत गई सो बात गई

Hello All,

I still remember one of my school's Hindi book poem of great poet Harivansh Rai Bachchanji.

Whenever I feel low spirited this poem helps me to rejuvenate me.

"Jo Beet Gayi So Baat Gayi"


जीवन में एक सितारा था
माना वह बेहद प्यारा था
वह डूब गया तो डूब गया
अंबर के आंगन को देखो
कितने इसके तारे टूटे
कितने इसके प्यारे छूटे
जो छूट गए फ़िर कहाँ मिले
पर बोलो टूटे तारों पर
कब अंबर शोक मनाता है
जो बीत गई सो बात गई

जीवन में वह था एक कुसुम
थे उस पर नित्य निछावर तुम
वह सूख गया तो सूख गया
मधुबन की छाती को देखो
सूखी कितनी इसकी कलियाँ
मुरझाईं कितनी वल्लरियाँ
जो मुरझाईं फ़िर कहाँ खिलीं
पर बोलो सूखे फूलों पर
कब मधुबन शोर मचाता है
जो बीत गई सो बात गई

जीवन में मधु का प्याला था
तुमने तन मन दे डाला था
वह टूट गया तो टूट गया
मदिरालय का आंगन देखो
कितने प्याले हिल जाते हैं
गिर मिट्टी में मिल जाते हैं
जो गिरते हैं कब उठते हैं
पर बोलो टूटे प्यालों पर
कब मदिरालय पछताता है
जो बीत गई सो बात गई

मृदु मिट्टी के बने हुए हैं
मधु घट फूटा ही करते हैं
लघु जीवन ले कर आए हैं
प्याले टूटा ही करते हैं
फ़िर भी मदिरालय के अन्दर
मधु के घट हैं,मधु प्याले हैं
जो मादकता के मारे हैं
वे मधु लूटा ही करते हैं
वह कच्चा पीने वाला है
जिसकी ममता घट प्यालों पर
जो सच्चे मधु से जला हुआ
कब रोता है चिल्लाता है
जो बीत गई सो बात गई


Hope it helps everyone of you, whenever you feel low spirited. :)

Removing Items from Silverlight ListBox on button click

Hello All,
Today on Silverlight forum one query was posted regarding deleting item from Listbox. In normal scenario if we have list of Items in Listbox and we want to delete any of the Items from the Listbox we select that Item and click on delete button which is outside the Listbox but he wanted to have delete button inside the Listbox with Textblock and Image. The best solution to this is ObservableCollection.One of the greatest advantage of ObservableCollection is it provides notifications when items get added, removed, or when the whole list is refreshed.

Here is what you have to do:

Xaml Code:



        <ListBox x:Name="lstEmployee" Width="180" Height="250" HorizontalAlignment="Left" VerticalAlignment="Top">
               <ListBox.ItemTemplate>
                        <DataTemplate>
                               <Canvas x:Name="LayoutRoot" Width="133.90" Height="26.50" Background="#F0F0F0"
HorizontalAlignment="Right">
                                      <Border Canvas.Left="30.40" BorderThickness="0.1,0.2,0.2,0.2" Height="26.50" Width="89" BorderBrush="#FF6262FF">
                                             <StackPanel Orientation="Vertical" HorizontalAlignment="Left" MaxWidth="133.90" Height="26.50" Width="120" Background="Transparent">
                                                    <StackPanel x:Name="stackPanelUserInfo" Orientation="Horizontal" MaxWidth="128.90">
                                                           <HyperlinkButton x:Name="hyperLinkButtonDisplayName" Content="{Binding Name}" IsTabStop="False"
Margin="2,0,0,0" FontFamily="Fonts/Fonts.zip#Segoe UI" FontSize="11" Foreground="#FF000099" FontWeight="Bold" VerticalAlignment="Top" Tag="{Binding Path=ID}"/>
                                                    </StackPanel>
                                                    <TextBlock x:Name="textBlockOccupation" Text="{Binding Occupation}" Padding="0,0,0,0" FontFamily="Fonts/Fonts.zip#Segoe UI" FontSize="9" Foreground="#FF999999" Margin="8,-3,0,0" HorizontalAlignment="Left" Height="13.90" Tag="{Binding Path=ID}"/>
                                              </StackPanel>
                                     </Border>
                              <Canvas x:Name="CanvasStatus" Height="26.50" Width="8.9" Canvas.Left="120" Canvas.Top="0" Background="#FF16E029" Tag="{Binding Path=ID}"/>
                              <Button x:Name="Closebtn" Height="25" Margin="133,2" Width="20" BorderThickness="1" Tag="{Binding Path=ID}" Click="btnRemove_Click">
                                    <Path Fill="#444444" Stretch="Fill" StrokeThickness="1" Height="10" Width="10" Data="F1M525.79325,203.7591L522.590125,206.962225L525.79325,210.16535L524.73075,211.22785L521.527625,208.024725L518.340125,211.212225L517.277625,210.149725L520.465125,206.962225L517.262,203.7591L518.3245,202.6966L521.527625,205.899725L524.73075,202.6966L525.79325,203.7591" UseLayoutRounding="False" Canvas.Top="1" />
                              </Button>
                   </Canvas>
            </DataTemplate>
       </ListBox.ItemTemplate>
 </ListBox>


Code Behind:

public class Employee

{

             public int ID { get; set; }


             public string Name { get; set; }


             public string Occupation { get; set; }
}
 
ObservableCollection employee = new ObservableCollection();

employee.Add(new Employee() { ID = 1, Name = "Nimish", Occupation = "CEO" });

employee.Add(new Employee() { ID = 2, Name = "Vikas", Occupation = "Module Leader" });

employee.Add(new Employee() { ID = 3, Name = "Pooja", Occupation = "Software Engg" });

employee.Add(new Employee() { ID = 4, Name = "Maya", Occupation = "Web Designer" });

employee.Add(new Employee() { ID = 5, Name = "Kiran", Occupation = "Jr Developer" });

employee.Add(new Employee() { ID = 6, Name = "Pragati", Occupation = "Software Engg" });

employee.Add(new Employee() { ID = 7, Name = "Lalit", Occupation = "Team Leader" });

employee.Add(new Employee() { ID = 8, Name = "Neha", Occupation = "HR" });

employee.Add(new Employee() { ID = 9, Name = "Sachin", Occupation = "Sr Developer" });employee.Add(new Employee() { ID = 10, Name = "Ishita", Occupation = "Module Leader" });


lstEmployee.ItemsSource = employee;

On Remove Button Click:
 
private void btnRemove_Click(object sender, RoutedEventArgs e)

{

           var emp = employee.Where(a => a.ID.Equals(((System.Windows.FrameworkElement)(e.OriginalSource)).Tag)).ToList();


            if (emp.Count == 1)
                     employee.Remove(emp.First());
}
 
Thats all we have to do. Download the Sample Code.
 
Happy coding :)

DataGrid Paging in Silverlight 3

Hello All,


A small example of Datagrid using DataPager control.


Xaml code:


<Data:DataGrid x:Name="myDatagrid" />
<Data:DataPager x:Name="myPager" Source="{Binding Path=ItemsSource, ElementName=myDatagrid}" PageSize="5" />


Code Behind:


using System.Window.Data;


namespace DataGridControls
{
           public partial class DatagridPaging : UserControl
         {
                       InitializeComponent();
                       PagedCollectionView  pagedcollectionview = new PagedCollectionView("H E L L O W O R L D".Split(' '));
                       myDatagrid.ItemsSource = pagedcollectionview;
         }
}


Hope that helps.


Comments are always welcome. Thank you.

Silverlight Installation Errors Codes

Awesome article about Silverlight Installation Error Codes with their cause and how to fix them. Check this.

Enjoy and Happy coding :) 

Happy Guddi Padwa/Ugadi :)

Hello all,

Wish you and your family Happy Guddi Padwa/Ugadi.








Warm Regards,

Varsha.

Square RadioButton in Silverlight

Hello All,


My project GUI has various screens with Radiobuttons given for user choice. These buttons are graphically circular in design, I thought of changing it to Square just for the sake of making the design look unique. So I did some changes in style and it was done.


Following is the Source code for the change of design from circular to square


Happy Coding :)

Silverlight and MySQL

Hello All,


I would like to share a new aspect in Silverlight. We all know that Silverlight doesn't support ADO.NET. You can not directly call ADO.NET code from SilverLight application but you can call a WCF service. You can convert Dataset into List and just pass it over to Silverlight Application Via WCF.


Here is one way you can use MYSQL with Silverlight.


I have just created a class called City and in the List object of City I have filled all the City Names and binded it with DataGrid.


You can download the source code from Project/Source Code.


Let me know if you find any issues with the Source code.


NOTE: I have not added mysql connection string so first put the connection string in WebConfig file in SilverlightAndMySQL.Services Project.


Happy Coding :)

Sr. No/Row Number for Silverlight 3 DataGrid

Hello All,


Let me first wish you all A Very Happy New Year!!!!


Few days back a query was posted on silverlight forum which says:


"I want to add a column in my datagrid control to show Serial Numbers. I want that column to be Constant i-e i dont want to make that serial number field a part of the objects in the collection binded to the ItemSource property of the Datagrid. On the other hand i would prefer a solution other than ValueConverter. Does datagrid itself gives some kind of support for this?? Or in what way it can be done through handling some event of datagrid in code behind??? "


Though I posted the reply, I was not satisfied with it as it was giving problem when Datagrid has paging.


Here is that reply to post: http://forums.silverlight.net/forums/t/156575.aspx


The problem here was when we give paging to datagrid, on each Page it was re-numbering from 1 instead of continuing with the numbers that ended on the previous page. After spending some time on it I could figure it out how make it work.
Here is the correct way:


Xaml Page:


<StackPanel Orientation="Vertical">
<Data:DataGrid x:Name="dgEmployee" SelectionMode="Single" Margin="5" AutoGenerateColumns="False"

Grid.Row="0" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False">
<Data:DataGrid.Columns>
<Data:DataGridTemplateColumn Header="Sr. No" Width="90">
<Data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="tbID"></TextBlock>
</DataTemplate>
</Data:DataGridTemplateColumn.CellTemplate>
</Data:DataGridTemplateColumn>

<Data:DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName" IsReadOnly="True" Width="90">
</Data:DataGridTextColumn>
<Data:DataGridTextColumn Binding="{Binding LastName}" Header="LastName" IsReadOnly="True" Width="90">
</Data:DataGridTextColumn>
</Data:DataGrid.Columns>
</Data:DataGrid>
<Data:DataPager x:Name="customerPager" PageSize="5" Source="{Binding Path=ItemsSource, ElementName=dgEmployee}"></Data:DataPager>
</StackPanel>


Code Behind:
#region Variables
int PageIndex = 0;

#endregion


#region Page Constructor
public MainPage()
{
        InitializeComponent();
        AttachEventHandlers();
        PagedCollectionView pagedcollectionview = new PagedCollectionView(Employee.GetSampleEmployeeList());
        dgEmployee.ItemsSource = pagedcollectionview;
        dgEmployee.Columns[0].IsReadOnly = true;
}
#endregion


#region Attach Event Handlers Method
void AttachEventHandlers()
{
       dgEmployee.LoadingRow += new EventHandler<DataGridRowEventArgs>(dgEmployee_LoadingRow);
}
#endregion


#region DataGrid Events
void dgEmployee_LoadingRow(object sender, DataGridRowEventArgs e)
{
        DataGridRow dgRow = DataGridRow.GetRowContainingElement(e.Row);
        TextBlock textblock = dgEmployee.Columns[0].GetCellContent(dgRow) as TextBlock;
        if (textblock != null)
        {
                if (e.Row.GetIndex() == 0)
               {
                        textblock.Text = ((customerPager.PageSize * customerPager.PageIndex) + 1).ToString();
                        PageIndex = (customerPager.PageSize * customerPager.PageIndex) + 1;
               }
               else
                        textblock.Text = (++PageIndex).ToString();
        }
}
#endregion


Comments are always welcome.


You can download SourceCode.


Happy Coding :)