SELECT name INTO #tables from sys.objects where type = 'U' while (SELECT count(1) FROM #tables) > 0 begin declare @sql varchar(max) declare @tbl varchar(255) SELECT top 1 @tbl = name FROM #tables SET @sql = 'drop table ' + @tbl exec(@sql) DELETE FROM #tables where name = @tbl end DROP TABLE #tables
Archive for » March, 2009 «
Sort and page the results
public SortDirection SortDir { get { if (ViewState["sortDirection"] == null) { ViewState["sortDirection"] = SortDirection.Ascending; } return (SortDirection)ViewState["sortDirection"]; } set { ViewState["sortDirection"] = value; } } DataSet ds = new DataSet(); DataView dv = new DataView(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); GridView1.DataSource = dv; GridView1.DataBind(); } } private DataView BindGrid() { ds = new Query(AnthemWeb.DAL.Item.Schema).ExecuteDataSet(); if (ViewState["sortExpr"] != null) { dv = new DataView(ds.Tables[0]); dv.Sort = (string)ViewState["sortExpr"]; } else { dv = ds.Tables[0].DefaultView; } return dv; } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataSource = BindGrid(); GridView1.DataBind(); } protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) { string stExp = e.SortExpression; string stDir = string.Empty; if (SortDir == SortDirection.Ascending) { SortDir = SortDirection.Descending; stDir = "DESC"; } else { SortDir = SortDirection.Ascending; stDir = "ASC"; } ViewState["sortExpr"] = e.SortExpression + " " + stDir; GridView1.DataSource = BindGrid(); GridView1.DataBind(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int selectedRowIndex; selectedRowIndex = GridView1.SelectedIndex; GridViewRow row = GridView1.Rows[selectedRowIndex]; string ID = row.Cells[0].Text; Response.Redirect("customer-details.aspx?ID=" + ID, false); } protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); }
Started this week to use Subsonic to generate my DAL. I got this handy reference from their forum for doing the INSERTS etc…
private void BindNames()
{
AddBook.DLL.AddressBookCollection list = new AddBook.DLL.AddressBookCollection().OrderByAsc("Name").Load();
this.ddNames.DataSource = list;
this.ddNames.DataTextField = "Name";
this.ddNames.DataValueField = "UserID";
this.ddNames.DataBind();
}
protected void btnSelect_Click(object sender, EventArgs e)
{
AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook(ddNames.SelectedValue);
this.tbName.Text = ab.Name;
this.tbSurname.Text = ab.Surname;
this.tbAddress.Text = ab.Address;
this.tbHomePhone.Text = ab.HomePhone;
this.tbMobilePhone.Text = ab.MobilePhone;
}protected void btnDelete_Click(object sender, EventArgs e)
{
AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook(ddNames.SelectedValue);
AddBook.DLL.AddressBook.Delete(ab.UserID);
BindNames();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook(ddNames.SelectedValue);
ab.Name = tbName.Text;
ab.Surname = tbSurname.Text;
ab.Address = tbAddress.Text;
ab.HomePhone = tbHomePhone.Text;
ab.MobilePhone = tbMobilePhone.Text;
ab.Save();
BindNames();
}protected void btnInsert_Click(object sender, EventArgs e)
{
AddBook.DLL.AddressBook ab = new AddBook.DLL.AddressBook();
ab.Name = tbName.Text;
ab.Surname = tbSurname.Text;
ab.Address = tbAddress.Text;
ab.HomePhone = tbHomePhone.Text;
ab.MobilePhone = tbMobilePhone.Text;
ab.Save();
BindNames();
}
Example page = www.mysite.com/pickup-golding.aspx
C# code
string loadedPageName = Path.GetFileName(Page.Request.PhysicalPath); Response.Write(loadedPageName);
Result = pickup-golding.aspx
