Thursday, April 28, 2011

Converting String To Type

Enum.Parse Method (Type, String)

http://msdn.microsoft.com/en-us/library/essfb559.aspx

Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.

using System;
[Flags] enum Colors { None=0, Red = 1, Green = 2, Blue = 4 };
public class Example{
public static void Main()
{
string[] colorStrings = { "0", "2", "8", "blue", "Blue", "Yellow", "Red, Green" };
foreach (string colorString in colorStrings)
{
try {
Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString);
if (Enum.IsDefined(typeof(Colors), colorValue) | colorValue.ToString().Contains(","))
Console.WriteLine("Converted '{0}' to {1}.", colorString, colorValue.ToString());
else
Console.WriteLine("{0} is not an underlying value of the Colors enumeration.", colorString);
}
catch (ArgumentException) {
Console.WriteLine("'{0}' is not a member of the Colors enumeration.", colorString);
}
}
}
}
// The example displays the following output:
// Converted '0' to None.
// Converted '2' to Green.
// 8 is not an underlying value of the Colors enumeration.
// 'blue' is not a member of the Colors enumeration.
// Converted 'Blue' to Blue.
// 'Yellow' is not a member of the Colors enumeration.
// Converted 'Red, Green' to Red, Green.

Tuesday, April 26, 2011

Database diagram support objects cannot be installed

"Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects."

Solution :
EXEC sp_dbcmptlevel 'yourDB', '90';
go
ALTER AUTHORIZATION ON DATABASE::yourDB TO "yourLogin"
go
use [yourDB]
go
EXECUTE AS USER = N'dbo' REVERT
go

Tuesday, February 22, 2011

Datalist Paging

Datalist Paging

public void BindList(){
PagedDataSource objPage = new PagedDataSource();


DataSet ds =new DataSet;
objPage.AllowPaging = true;
objPage.DataSource = ds.Tables["Gallery"].DefaultView;
objPage.PageSize = 8;

objPage.CurrentPageIndex = CurrentPage;

lbtnNext.Enabled = !objPage.IsLastPage;
lbtnPrev.Enabled = !objPage.IsFirstPage;


datalist1.DataSource = objPage;
datalist1.DataBind();
}
}

private void lbtnPrev_Click(object sender, System.EventArgs e)
{
CurrentPage -=1;
BindList();
}

private void lbtnNext_Click(object sender, System.EventArgs e)
{
CurrentPage +=1;
BindList();
}

Wednesday, July 28, 2010

VB.NET and C# Comparison

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
VB.NET and C# Comparison

Java and C# Comparison

http://www.harding.edu/fmccown/java_csharp_comparison.html
Java and C# Comparison

Tuesday, July 13, 2010

Automatic Redirect Page Using HTML

HEAD
META HTTP-EQUIV="refresh" CONTENT="5;URL=http://www.google.com/"
End HEAD
Your browser should automatically take you there in 5 seconds.
If it doesn't please go to http://www.google.com

Thursday, July 1, 2010

Getting Gridview Row Index in Row Command Event

GridViewRow rowSelect = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
int i = rowSelect.RowIndex;

OR

GridViewRow rowSelect = ((ImageButton)sender).Parent.Parent as GridViewRow;
int i = rowSelect.RowIndex;

OR

Bind in Button CommandArgument
((GridViewRow) Container).RowIndex

OR
GridView Row index by control
CheckBox chkBox = (CheckBox) sender;
GridViewRow gRow = (GridViewRow)chkBox.NamingContainer;

Monday, June 14, 2010

Export ASP.Net GridView to PDF and XLS using iTextSharp

http://www.aspsnippets.com/Articles/Export-ASP.Net-GridView-to-PDF-with-Custom-Columns-Widths-using-iTextSharp.aspx

http://sourceforge.net/projects/itextsharp/

Adding Custom Header in Gridview

protected void gViewEdit_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView gView = (GridView)sender;
GridViewRow gViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell tblCell = new TableCell();
tblCell.Text = "Admission Report";
tblCell.ColumnSpan = 13;
tblCell.HorizontalAlign = HorizontalAlign.Center;
tblCell.Font.Size = 16;
tblCell.Font.Bold = true;
gViewRow.Cells.Add(tblCell);
gView.Controls[0].Controls.AddAt(0, gViewRow);
}
}