void GetAllCustomer() { string sqlstr; sqlstr = "select CustomerID,CompanyName, RegionID, Picture from Customers "; CustomerGrid.DataSource = mydb.BuildDataTable(sqlstr);; CustomerGrid.DataBind(); }
public void BindGrid() { try { string cstring = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; MySqlConnection con = new MySqlConnection(cstring); MySqlCommand cmd = new MySqlCommand("SELECT CustomerID,CompanyName,ContactTitle,City,PostalCode,Phone,Fax from Customers", con); MySqlDataAdapter sda = new MySqlDataAdapter(); sda.SelectCommand = cmd; DataSet ds = new DataSet(); sda.Fill(ds); CustomerGrid.DataSource = ds; CustomerGrid.DataBind(); } catch (Exception) { Response.Redirect(objconstmsg.strerrorpage, false); } }
private void BindData() { _customers = _repo.GetAll(); CustomerGrid.DataSource = _customers; CustomerGrid.DataBind(); }
// Checks the Order by value and fires the query to display the customer information by given order and display the data grid. // private void DropOrderBy_SelectedIndexChanged(object sender, System.EventArgs e) // { // if(DropOrderBy.SelectedIndex == 0) // { // MessageBox.Show("Please Select Display Order"); // return; // } // string order_by = "Cust_Name"; // if(DropOrderBy.SelectedItem.Text == "Customer Type") // order_by = "Cust_Type"; // // if(DropOrderBy.SelectedItem.Text == "Customer City") // order_by = "City"; // // try // { // SqlDataReader SqlDtr = null; // // dbobj.SelectQuery("Select * from Customer order by "+order_by+" asc",ref SqlDtr); // CustomerGrid.DataSource = SqlDtr; // CustomerGrid.DataBind(); // // if(CustomerGrid.Items.Count==0) // { // MessageBox.Show("Data not available"); // CustomerGrid.Visible=false; // } // else // { // CustomerGrid.Visible=true; // } // SqlDtr.Close (); // } // catch(Exception ex) // { // CreateLogFiles.ErrorLog("Form:CustomerDataMining.aspx,Method:DropOrderBy_SelectedIndexChanged EXCEPTION "+ex.Message+" User: "******"Servosms"]); string sql = ""; string Cust_Name = ""; if (DropSearchBy.SelectedIndex == 0) { sql = "Select * from Customer"; } else { if (DropValue.Value == "All") { sql = "Select * from Customer"; } else if (DropSearchBy.SelectedIndex == 1) { //coment by vikas 25.05.09 sql="Select * from Customer where cust_name='"+DropValue.Value+"'"; /*******Add by vikas sharma 25.05.09************************/ Cust_Name = DropValue.Value.Substring(0, DropValue.Value.IndexOf(":")); sql = "Select * from Customer where cust_name='" + Cust_Name.ToString() + "'"; /*******Add by vikas sharma 25.05.09************************/ } /******Add by vikas 17.11.2012*********************/ else if (DropSearchBy.SelectedIndex == 2) { sql = "Select * from Customer where cust_id in(select cust_id from customer c,customertype ct where c.cust_type=ct.customertypename and group_Name ='" + DropValue.Value + "')"; } else if (DropSearchBy.SelectedIndex == 3) { sql = "Select * from Customer where cust_id in(select cust_id from customer c,customertype ct where c.cust_type=ct.customertypename and sub_group_Name ='" + DropValue.Value + "')"; /****End******/ } else if (DropSearchBy.SelectedIndex == 4) { sql = "Select * from Customer where state='" + DropValue.Value + "'"; } else if (DropSearchBy.SelectedIndex == 5) { sql = "Select * from Customer where city='" + DropValue.Value + "'"; } else if (DropSearchBy.SelectedIndex == 6) { sql = "Select * from Customer where ssr=(select emp_id from employee where emp_name='" + DropValue.Value + "')"; } } sql += " order by cust_name"; SqlDataAdapter da = new SqlDataAdapter(sql, sqlcon); DataSet ds = new DataSet(); da.Fill(ds, "customer"); DataTable dtcustomer = ds.Tables["customer"]; //da.Fill(ds,"beat_master","machanic_entry","customermechanicentry ","customer"); //DataTable dtcustomer=ds.Tables["beat_master","machanic_entry","customermechanicentry ","customer"]; DataView dv = new DataView(dtcustomer); dv.Sort = strorderby; Cache["strorderby"] = strorderby; if (chkTesting.Checked) { CustomerTestGrid.DataSource = dv; } else { CustomerGrid.DataSource = dv; } if (dv.Count != 0) { if (chkTesting.Checked) { CustomerTestGrid.DataBind(); CustomerTestGrid.Visible = true; CustomerGrid.Visible = false; } else { CustomerGrid.DataBind(); CustomerTestGrid.Visible = false; CustomerGrid.Visible = true; } } else { CustomerGrid.Visible = false; CustomerTestGrid.Visible = false; MessageBox.Show("Data Not Available"); } sqlcon.Dispose(); }
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e) { CustomerGrid.PageIndex = e.NewPageIndex; BindGrid(); CustomerGrid.DataBind(); }