Search This Blog

Friday, April 3, 2015

How to change the row index by clicking image up and down

You can get the row ID from OnRowCommand.

 protected void gridview_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            DataTable dt = new DataTable();
            dt = Getdetails();                  ///Get existing details from gridview
            int index = Convert.ToInt32(e.CommandArgument);     ///Get row ID
            string Command = Convert.ToString(e.CommandName); ///Get Commandname
            DataRow selectedRow = dt.Rows[index];                        ///Get the selected Row
            DataRow newRow = dt.NewRow();                                 ///Create a new row
            newRow.ItemArray = selectedRow.ItemArray;   ///Insert selected row into new row
            dt.Rows.Remove(selectedRow);                                      ///Remove selected row
            if (Command == "Up")
            {
                dt.Rows.InsertAt(newRow, index - 1);                    
            }
            else if (Command == "Down")
            {
                dt.Rows.InsertAt(newRow, index + 1);
            }
            gridview.DataSource = dt;
            gridview.DataBind();                             ///Set details into grid again
            ViewState["WFtable"] = dt;
            Setdetails(dt);                
        }


I hope this will help you guys.

thanks.

Degrade your IE browser

Some of your contents may not support in IE browser higher versions.
So we can degrade to down versions by following:

In your master page you can see a tag like:
<head runat="server">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
</head>

In content you can change the version of your browser:
<meta http-equiv="X-UA-Compatible" content="IE=9" />

Get sharepoint SPList ID

Navigate to the SharePoint list using the browser.
Select the Settings + List Settings menu command.
Copy the Url from the browser address bar into Notepad. It will look something like:
http://moss2007/ProjectX/_layouts/listedit.aspx?List=%7B26534EF9%2DAB3A%2D46E0%2DAE56%2DEFF168BE562F%7D

Delete everying before and including “List=”.
Change “%7B” to “{”
Change all “%2D” to “-“
Chnage “%7D” to “}”
You are now left with the Id:

{26534EF9-AB3A-46E0-AE56-EFF168BE562F}

Simple Ways to become a best programmer...

1. Never ever duplicate code

Avoid duplicating code at all costs. If you have a common code segment used in a few different places, refactor it out into its own function. Code duplication causes confusion among your colleagues reading your code, it causes bugs down the line when the duplicated segment is fixed in one location and not the others and it bloats the size of your code-base and executable. With modern languages its become possible to get really good at this, for example here is a pattern that used to be hard to solve before delegates and lambdas came along:

/// <summary>
/// Some function with partially duplicated code
/// </summary>
void OriginalA()
{
DoThingsA();

// unique code

DoThingsB();
}

/// <summary>
/// Another function with partially duplicated code
/// </summary>
void OriginalB()
{
DoThingsA();

// unique code

DoThingsB();
}
But now we can refactor the shared part of both functions and rewrite using a delegate:

/// <summary>
/// Encapsulate shared functionality
/// </summary>
/// <param name="action">User defined action</param>
void UniqueWrapper(Action action)
{
DoThingsA();

action();

DoThingsB();
}

/// <summary>
/// New implmentation of A
/// </summary>
void NewA()
{
UniqueWrapper(() =>
{
// unique code
});
}

/// <summary>
/// New implementation of B
/// </summary>
void NewB()
{
UniqueWrapper(() =>
{
// unique code
});
}

2. Notice when you start distracting yourself

When you find yourself flicking to facebook or twitter instead of working on a problem its often a sign that you need to take a short break. Go grab a coffee away from your desk and talk to your colleagues for 5 minutes or so. Even though this seems counter intuitive, you will be more productive in the long run.

3. Don’t rush the solution out the door

When under pressure to produce a solution to a problem, or to fix a bug, its very easy to get carried away and find yourself rushing, or even missing out your usual crucial testing cycle completely. This can often result in more problems and will make you look less professional in the eyes of your boss and colleagues.

4. Test your finished code

You know what your code is supposed to do, and you’ve likely tested that it works, but you really need to prove it. Analyse all the potential edge cases and make a test which confirms that your code performs as expected under all possible conditions. If there are parameters, send values outside of the expected range. Send null values. If you can, show your code to a colleague and ask them to break it. Unit testing is a formalised approach to this.

5. Code review

Before you promote your code into source control, sit down with a colleague and explain exactly what your change does. Often just by doing this you’ll recognise mistakes in your own code without your colleague saying a word. It’s much, much more effective than just reviewing your own work.

6. Write less code

If you find yourself writing a lot of code to do something simple, you’re probably doing it wrong. A good example is the lowly boolean:

if (numMines > 0)
{
   enabled=true;
}
else
{
   enabled=false;
}
When you could just write:

enabled = numMines > 0;
The less code you write the better. Less to debug, less to refactor, less to go wrong. Use with moderation; readability is just as important, you don’t want to make your code less readable by doing this.

7. Strive for elegant code

Elegant code is highly readable and solves the problem at hand with the smallest amount of code and machine action possible. Its quite difficult to achieve elegant code in all circumstances but after programming for a while you start to get a feel for what it looks like. Elegant code cannot be improved by refactoring anything. It makes you happy to look at it. You are proud of it. For example here is what I consider to be an elegant way of computing the area of a convex polygon:

static public double GetConvexPolygonArea(Vector2[] vertices)
{
double area = 0;
for (int i = 0; i < vertices.Length; i++)
{
Vector2 P0 = vertices[i];
Vector2 P1 = vertices[(i + 1) % vertices.Length];

area += P0.Wedge(P1);
}

return area / 2;
}

8. Write self documenting code

Comments are a very important part of programming for obvious reasons, but self documenting code can be even better because it makes it possible to understand code just by reading it. Function and variable names can often be deftly chosen so that when put together with the language semantics the code becomes readable even to non programmers. For example:

void DamagePlayer(Player player, int damageAmount)
{
if (!player.m_IsInvincible && !player.m_IsDead)
{
player.InflictDamage( damageAmount );
}
}
Self documenting code is not a substitute for comments. Use comments to describe ‘why’, self documenting code describes ‘what’.

9. Don’t use magic numbers

Numbers just inserted into the code are bad practice because there is nothing to describe what they represent. This is compounded by duplication; where the same number is used in multiple different places in the code. One will get changed and the others missed leading to bugs. Always use a named constant to describe the value you want to represent, even if it is only used in one place.

10. Don’t do manual labour

Humans are very good at making mistakes when doing a series of actions. If you have a build deployment process which is more than one step long, you’re doing it wrong. Automate as much as possible, reduce the chance of human error. This is especially important with tasks which you perform a lot.

11. Avoid premature optimisation

When you start optimising part of your already functioning code you risk breaking the functionality. Optimisation should only be performed in response to performance analysis, hopefully carried out towards the end of a project. Optimising before this analysis stage wastes time and can introduce bugs.

Monday, January 5, 2015

UpdatePanel control

The UpdatePanel control is probably the most important control in the ASP.NET AJAX package. It will AJAX'ify controls contained within it, allowing partial rendering of the area. We already used it in the Hello world example, and in this chapter, we will go in depth with more aspects of the control.

The <asp:UpdatePanel> tag has two childtags - the ContentTemplate and the Triggers tags. The ContentTemplate tag is required, since it holds the content of the panel. The content can be anything that you would normally put on your page, from literal text to web controls. The Triggers tag allows you to define certain triggers which will make the panel update it's content. The following example will show the use of both childtags.

1. AsyncPostBackTrigger

it is the one which enforces Asynchonous post back of the Page.., i.e. the AJAX way. The data will be transacted without full post back. When you are using functionalities like login, you may use this.

Ex. You are having two dropDowns Viz., Countries and States. the states should be loaded when a country is selected and it should be changed on Countries change.

You may use AsyncPostBackTrigger in this scinario., which will populate the states ddl without full post back.

2. PostBackTrigger

It is the one which does not follow the AJAX functioalities., but the full post back as usually(as Without using UpdatePanel). Situtions are there where you would not like to enforce Partial Post back (as explained in Point 1. above). Like you are having FileUpload Control withing the UpdatePanel and when you do it by AsyncPostBack, you will not get any values to the server. It requires Full PostBack. in such a case you should use this trigger.

thank you.

Have you ever wonder which country is the best to live for IT engineers?

Below a list of 10 best countries to live for software engineers.

10. Canada
I. Median annual pay for software engineer – $57500

II. Position in the world ranking of “Happiness Index – experienced well-being” - 2

III. Position in the ranking of  “Best for workers: Countries” – 11

9. New Zealand
I.Median annual pay for software engineer – $59600

II.Position in the world ranking of “Happiness Index” - 17

III.Position in the ranking of  “Best for workers: Countries” – 8

8. Sweden
I. Median annual pay for software engineer – $61400

II. Position in the world ranking of “Happiness Index” - 5

III. Position in the ranking of  “Best for workers: Countries” – 8

7. Germany
I. Median annual pay for software engineer – $63800

II. Position in the world ranking of “Happiness Index” - 27

III. Position in the ranking of  “Best for workers: Countries” – 20

6. Australia
I. Median annual pay for software engineer – $65900

II. Position in the world ranking of “Happiness Index” - 8

III. Position in the ranking of  “Best for workers: Countries” – 14

5. Israel
I. Median annual pay for software engineer – $70700

II. Position in the world ranking of “Happiness Index” - 10

III. Position in the ranking of  “Best for workers: Countries” – 10

4. Denmark
I. Median annual pay for software engineer – $71500

II. Position in the world ranking of “Happiness Index” - 1

III. Position in the ranking of  “Best for workers: Countries” – 4

3. United States
I. Median annual pay for software engineer – $76000

II. Position in the world ranking of “Happiness Index” - 16

III. Position in the ranking of  “Best for workers: Countries” – 7

2. Norway
I. Median annual pay for software engineer – $81400

II. Position in the world ranking of “Happiness Index” - 3

III.Position in the ranking of  “Best for workers: Countries” – 6

1. Switzerland
I. Median annual pay for software engineer – $104200

II. Position in the world ranking of “Happiness Index” - 6

III.Position in the ranking of  “Best for workers: Countries” – 24

For more: Click here

Friday, January 2, 2015

error: $Resources:core,ImportErrorMessage

Today i have faced an exception while importing webpart into a wiki page.

error: $Resources:core,ImportErrorMessage

we can overcome this issue.

Solution : Visual Studio -> Build -> Select 'Retract' -> Clean solution -> Build and deploy.

If it doesn't  solve this please check your connection string name is correct or not. it may cause the issue.


thank you.



Restricting Custom People Picker to only one Sharepoint group programatically

Refer the following script files in your page,     <!-- For People Picker -->     <script type="text/javascript" src...