Thursday, July 29, 2010

Guid to String and viceversa

Label1.Text= TypeDescriptor.GetConverter(myGuid).ConvertTo(myGuid, typeof(string)).ToString();
Label2.Text= TypeDescriptor.GetConverter(myGuid).ConvertFrom(myGuidString).ToString();

Tuesday, July 27, 2010

Choosing Controls based on Insert ,Update ,Delete

If you want to insert new records, your only choices are DetailsView and FormView.

If you want to update or delete data (but not necessarily insert new records), choose GridView, DetailsView, or FormView. Although DataList is capable of providing UI for editing, it does not take advantage of the data source’s ability to do this automatically like GridView, and you’ll need to write custom code to make it work. Refer to an ASP.NET v1 reference for more information (the topic is outside the scope of this book).

If you only want to display read-only values, you can use any of the templated controls .

Choosing a control based on formatting and layout of the data records:

If you want to display multiple data records at the same time, choose between GridView, DataList, and Repeater:

GridView: Displays each data record as a row in a table. Fields of the data record are displayed in the table cells (one field per cell, or using a template, as many fields per cells as you need). The contents of each cell are defined by the TemplateField.ItemTemplate property.

DataList: Displays each data record as a cell in a table. The number of data records per row in the table is determined by the DataList’s RepeatColumns property. The ItemTemplate property allows you to define the template rendering of each data record within the table cell.

Repeater: Displays each data record as a user-defined item, defined by the Repeater’s ItemTemplate property. There is no built-in table for layout, so the items simply flow from one to the next (within a tag, so styles are applied).

If you want to display one record at a time, choose between DetailsView and FormView:

DetailsView: Displays each data record as a table of two columns, where each row typically contains a single field (the left cell is the header and the right cell the value). Using TemplateField, you can define the contents of each value cell using the TemplateField.ItemTemplate property.

FormView: Displays each data record as a single cell in a table with one row. The contents of the table cell are defined by the FormView’s ItemTemplate property.


=================================
GridView
DataList
Repeater
DetailsView
Form View

From version 1.x?
No
Yes
Yes
No
No

Number of records shown at once
Multiple
Multiple
Multiple
Single
Single

Can update records?
Yes
No[*]
No
Yes
Yes

Can delete records?
Yes
No[*]
No
Yes
Yes

Can insert records?
No
No
No
Yes
Yes

Can select records?
Yes
No[*]
No
Yes[**]
Yes[**]

Supports paging?
Yes
No
No
Yes
Yes

Renders data record as...
Row in multicolumn table
Cell in multirow/column table
Item in a (no table)
Single table of two columns
Single cell in a one-row table

Templates are optional?
Yes
No
No
Yes
No



Supports header/footer


Yes


Yes


Yes


Yes


Yes

GridView

Template Properties
EmptyDataTemplate
PagerTemplate
TemplateField
AlternatingItemTemplate
EditItemTemplate
FooterTemplate
HeaderTemplate
ItemTemplate

GridView repeats Template Field.ItemTemplate once per row for each record in the data source.

--------------------------------------------------------------------
DetailsView

EmptyDataTemplate
PagerTemplate
HeaderTemplate
FooterTemplate
TemplateField
Alternating-ItemTemplate
EditItemTemplate
FooterTemplate
HeaderTemplate
InsertItemTemplate
ItemTemplate

DetailsView renders TemplateField.ItemTemplate for field’s data cell the current record in the data source.

--------------------------------------------------------------------

FormView

EmptyDataTemplate
PagerTemplate
HeaderTemplate
FooterTemplate
ItemTemplate
EditItemTemplate
InsertItemTemplate

FormView renders the ItemTemplate for the current record in the data source.

--------------------------------------------------------------------
DataList

HeaderTemplate
FooterTemplate
AlternatingItemTemplate
ItemTemplate
EditItemTemplate
SelectedItemTemplate
SeparatorTemplate

DataList repeats the ItemTemplate once for each record in the data source

----------------------------------------------------
Repeater

HeaderTemplate
FooterTemplate
AlternatingItemTemplate
ItemTemplate
SeparatorTemplate

Repeater repeats the ItemTemplate once for each record in the data source.

Monday, July 26, 2010

Master Details Gridview

If you don't wanna display anything till any selected in Master Control then set CancelSelectOnNullParameter = True and remove a default from the master control

Friday, July 23, 2010

Gridview RowCOmmand

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{}

e.commandname =will give you the name of the which command name button is clicked. for e.g.
In Gridview colums we have

asp:ButtonField CommandName="Buy" Text="Buy"
asp:ButtonField CommandName="Sell" Text="Sell"

if (e.CommandName == "Buy")
{
Response.Write("You Bought: " + GridView1.DataKeys[rowIndex].Value);
}
else if (e.CommandName == "Sell")
{
Response.Write("You Sold: " + GridView1.DataKeys[rowIndex].Value);
}

e.CommandArgument:which will be the index of the clicked row within the record set.

DataFormatString for Gridview

Letter Code Format Example Result
C Currency with currency sign {0:C2} $3.14 Note rounding

E Exponential {0:E4} 3.1416E+000

F Fixed {0:F3} 3.142 Note rounding

G General {0:G3} 3.14
Same as currency but without symbol

P Percent {0:P0} %314
(Value must be 0.0314 to get %3.14)
dates and times

d (Lowercase d) Short date pattern {0:d} 1/13/2006

D (Uppercase D) Long date pattern {0:D} Friday, January 13, 2006

t (Lowercase t) Short time pattern {0:t} 2:23 PM

T (Uppercase T) Long time pattern and date {0:T} 2:23:45 PM

F (Uppercase F) Short time pattern and date {0:F} Friday, January 13, 2006 2:23:45 PM


m or M (Either case) Month and day pattern {0:m} January 13

y or Y (Either case) Year and month pattern {0:y} January 2006



To add text you as Literral String you must off HtmlEncode

HtmlEncode="false"
DataFormatString="My prefix {0:x} My suffix"

Saturday, July 17, 2010

Get Names from Enum into Dropdownn list

In Order to get the names from the dropdown list from enumeration

public enum ProjectStatuses
{
NotStarted, InProgress, Completed
};

ddlPaymentStatus.DataSource = Enum.GetNames(typeof(ProjectStatuses));
ddlPaymentStatus.DataTextField = "Key";
ddlPaymentStatus.DataValueField = "Value";
ddlPaymentStatus.DataBind();

ProjectStatuses=Name of the Enum
ddlPaymentStatus=Name of Dropdown list

Also we can make a generic function for binding
//function to bind the dropdown list with enumeration
public static Hashtable BindToEnum(Type enumType)
{
//get the names from the enumeration
string[] names = Enum.GetNames(enumType);
//get the values from the enumeration
Array values = Enum.GetValues(enumType);

//turn this into hashtable
Hashtable ht = new Hashtable();
for (int i = 0; i < names.Length; i++)
{
ht.Add(names[i], values.GetValue(i));


}
return ht;
}

Thursday, July 8, 2010

Problem Steps Recorder

Problem Steps Recorder can be used to automatically capture the steps performed by a user on a computer, including a text description of where they clicked and a picture of the screen during each click. This capture is then automatically saved to a file that can be used by a support professional to help the user troubleshoot the issue or understand what steps were taken by the user.

Note that they’re still in beta, and this feature is not complete. For example, it won’t record typed text, which means it is TOTALLY USELESS for command prompts or PowerShell commands or even outputs, but if properly guided, the user can add his own comments for any screenshot.

http://technet.microsoft.com/en-us/windows/dd320286.aspx

Metadata feature of .net 4.0

In order to add the metadata dynamically in .net 4.0 you could do following:

Suppose you need to get the state from the URL then you do :
string stateid=Page.RouteData.Values["state"] as string;
new state id should be in stateid.

Now add the metadata
Page.MetaDescription="A List of states in "+stateid;
Also we can set keywords with Page.MetaKeywards

And this would include the meatdata in the View Source section dynamically.

Thursday, July 1, 2010

How to Backup Your Internet Explorer 8 Favorites

•On the right hand side of the browser look for the word "Tools." Click on the arrow on the right hand side of "Tools."

•Step 2
Scrolls down to "Toolbars" and verify that "Menu Bar" has a check mark. If not, simple click on "Menu Bar."

•Step 3
You will now see the menu bar right on the upper left hand side. Click on "File" and scroll down to "Import and Export."

•Step 4
Select "Export to a file" and hit next. Select "Favorites" and then hit next.

•Step 5
You will see that "Favorites" is now highlight. Double click on "Favorites" so the everything below "Favorites" collapses into the "Favorites" folder and hit next.

•Step 6
You will see that the file name is called "bookmark.htm" and the file location will be "My Documents." Click Export and then finish.

•Step 7
Copy the file "bookmark.htm" to an external Hard Drive or USB/Flash drive.