using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace Query2 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnExecute_Click(object sender, EventArgs e) { string query = string.Empty; query = txtQuery.Text.Trim(); ClsManager obj = new ClsManager(); IExecuteQuery execute = (IExecuteQuery)obj; try { if (query.Length > 0) { if (query.ToLower().StartsWith("select")) { DataSet ds = new DataSet(); ds = execute.GetQueryResult(query); if (ds.Tables[0].Rows.Count > 0) { ViewState["SortExpr"] = null; gv.DataSource = ds; gv.DataBind(); } else { lblMsg.Visible = true; lblMsg.Text = "No Record Found"; } } else { lblMsg.Visible = true; lblMsg.Text = "Please Enter Valid Select Query."; } } else { lblMsg.Visible = true; lblMsg.Text = "Please Enter Query."; } } catch (Exception) { lblMsg.Visible = true; lblMsg.Text = obj.SqlEception; } } protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e) { string query = string.Empty; query = txtQuery.Text.Trim(); ClsManager obj = new ClsManager(); IExecuteQuery execute = (IExecuteQuery)obj; gv.PageIndex = e.NewPageIndex; DataSet ds = new DataSet(); ds = execute.GetQueryResult(query); if (ds.Tables[0].Rows.Count > 0) { gv.DataSource = ds; gv.DataBind(); } else { lblMsg.Visible = true; lblMsg.Text = "No Record Found"; } } protected void gv_Sorting(object sender, GridViewSortEventArgs e) { if (ViewState["sortexpre"] == null) { string[] sortorder = ViewState["sortexpre"].ToString().Split(','); if (sortorder[0] == e.SortExpression) { if (sortorder[1] == "ASC") { ViewState["sortexpre"] = e.SortExpression + " " + "DESC"; } else { ViewState["sortexpre"] = e.SortExpression + " " + "ASC"; } } else { ViewState["sortexpre"] = e.SortExpression + " " + "ASC"; } string query = string.Empty; query = txtQuery.Text.Trim(); ClsManager obj = new ClsManager(); IExecuteQuery execute = (IExecuteQuery)obj; DataSet ds = new DataSet(); ds = execute.GetQueryResult(query); if (ds.Tables[0].Rows.Count > 0) { gv.DataSource = ds; gv.DataBind(); } else { lblMsg.Visible = true; lblMsg.Text = "No Record Found"; } } } } }
Friday, September 5, 2014
Subscribe to:
Posts (Atom)