Thursday, July 2, 2009

Gridview Tips and Tricks

http://www.dotnetcurry.com/ShowArticle.aspx?ID=107

generating random passwords

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
Label1.Text = "Please enter a password length (e.g. 8)";
}
TextBox1.Text = "8";
}

public static string CreateRandomPassword(int PasswordLength)
{
string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
Random randNum = new Random();
char[] chars = new char[PasswordLength];
int allowedCharCount = _allowedChars.Length;

for (int i = 0; i < PasswordLength; i++)
{
chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
}

return new string(chars);
}

protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
string myInt = TextBox1.Text.ToString();
Label1.Text = "Your generated password is: " + CreateRandomPassword(int.Parse(myInt));
}
}
}

Validation Controls Tips and Tricks

http://www.dotnetcurry.com/ShowArticle.aspx?ID=121

Wednesday, June 24, 2009

Using javascript for checkall in gridview

script language="javascript" type="text/javascript"
function selectall(status)
{
var gridview=document.getElementById("gridview1");
for(var i=1;i
Columns>


asp:TemplateField>
HeaderTemplate>
asp:CheckBox runat="Server" ID="chkall" onclick="javascript:selectall(this.checked);" />
/HeaderTemplate>
ItemTemplate>
asp:CheckBox runat="server" ID="chk1" />
/ItemTemplate>
/asp:TemplateField>
asp:BoundField DataField="ename" HeaderText="empname" ReadOnly="true" />
/Columns>
/asp:GridView>

Monday, June 15, 2009

Retrieve two tables of data at the same time by using data reader

Include 2 select statements either in a stored procedure or in a select command and call the ExecuteReader() method on the command object. This will automatically fill the DataReader with 2 Tables of data.

The datareader will always return the data from first table only. If you want to get the second table then you need to use ReaderObject.NextResult() method. The NextResult() method will return true if there is another table.

Example:


SqlConnection con = new SqlConnection("trusted_connection=yes;database=northwind;server=localhost");
SqlCommand cmd = new SqlCommand("select * from categories;select * from products", con);
con.Open();

SqlDataReader dr=cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();


while (dr.NextResult())
{
GridView2.DataSource = dr;
GridView2.DataBind();

}

Wednesday, June 10, 2009

Open a web page in a new window

The following HTML code will enable you to open a web page in a new window:

A HREF="http://www.yourdomain.com" TARGET="_blank"

If you're linking to a lot of other web sites within your web page and would like to open all of your links in a new window, this HTML code is for you.

The following HTML code will enable you to open all of your links in a new window. Place this code between your HEAD tag within your HTML:

base target="main"