protected void SearchEvent(object sender, EventArgs e) { string SearchQuery = "SELECT * FROM View_Companydetails WHERE View_Companydetails.CompanyName LIKE '" + TBSearch.Text.Trim() + "%'"; DataSet DSRecord = SqlHelper.ExecuteDataset(Connection.connect(), CommandType.Text, SearchQuery); if (DSRecord.Tables[0].Rows.Count > 0) { GVCompany.DataSource = DSRecord.Tables[0]; GVCompany.DataBind(); } else { GVCompany.EmptyDataText = "No Record Found !"; GVCompany.DataBind(); } foreach (GridViewRow Row in GVCompany.Rows) { Label lblStatus = (Label)Row.FindControl("lblStatus"); LinkButton LBEdit = (LinkButton)Row.FindControl("LBEdit"); LinkButton LBDelete = (LinkButton)Row.FindControl("LBDelete"); if (lblStatus.Text == "Active") { lblStatus.CssClass = "label label-success"; LBEdit.Enabled = true; LBDelete.Enabled = true; } else { lblStatus.CssClass = "label label-danger"; LBEdit.Enabled = false; LBDelete.Enabled = false; } } }
private void BindGVCompany() { string SelectQuery = "SELECT * FROM View_Companydetails"; DataSet DSRecord = SqlHelper.ExecuteDataset(Connection.connect(), CommandType.Text, SelectQuery); if (DSRecord.Tables[0].Rows.Count > 0) { GVCompany.DataSource = DSRecord.Tables[0]; GVCompany.DataBind(); } else { GVCompany.EmptyDataText = "No Record Found !"; GVCompany.DataBind(); } foreach (GridViewRow Row in GVCompany.Rows) { Label lblStatus = (Label)Row.FindControl("lblStatus"); LinkButton LBEdit = (LinkButton)Row.FindControl("LBEdit"); LinkButton LBDelete = (LinkButton)Row.FindControl("LBDelete"); if (lblStatus.Text == "Active") { lblStatus.CssClass = "label label-success"; LBEdit.Enabled = true; LBDelete.Enabled = true; } else { lblStatus.CssClass = "label label-danger"; LBEdit.Enabled = false; LBDelete.Enabled = false; } } }
public void FetchCompany() { CompanyDAL CompDAL = new CompanyDAL { ConnectionString = ConfigurationManager.ConnectionStrings["MySQLTest"].ToString() }; GVCompany.DataSource = CompDAL.GetCompany(null); GVCompany.DataBind(); }
public void FillGrid() { try { DataTable dt_ = new DataTable(); //dt_ = DBConnection.GetQueryData("select rtrim('[' + CAST(ProductTypeID AS VARCHAR(200)) + ']-' + ProductTypeName ) as [ProductTypeName], ProductTypeID from tbl_Companies"); dt_ = DBConnection.GetQueryData("select CompanyId, Name from tbl_Companies"); GVCompany.DataSource = dt_; GVCompany.DataBind(); ViewState["Company"] = dt_; } catch (Exception ex) { // throw; ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); lblalert.Text = ex.Message; } }
private void SearchRecord() { try { FillGrid(); DataTable _dt = (DataTable)ViewState["Company"]; DataView dv = new DataView(_dt, "Name LIKE '%" + TBSearchCompany.Text.Trim().ToUpper() + "%'", "[Name] ASC", DataViewRowState.CurrentRows); DataTable dt_ = new DataTable(); dt_ = dv.ToTable(); GVCompany.DataSource = dt_; GVCompany.DataBind(); ViewState["Company"] = dt_; } catch (Exception ex) { // throw; ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); lblalert.Text = ex.Message; } }
protected void GVCompany_PageIndexChanging(object sender, GridViewPageEventArgs e) { GVCompany.PageIndex = e.NewPageIndex; BindGVCompany(); GVCompany.DataBind(); }