public void FillGrid() { try { //Sales Order using (SqlCommand cmd = new SqlCommand()) { /*cmd.CommandText = " select top 20 ROW_NUMBER() OVER(ORDER BY tbl_MPos.Mposid DESC) AS [ID],tbl_Mpos.Mposid,tbl_Mpos.BillNO,billdat,left(billtim,8) as [billtim], tbl_MPos.CustomerName,Customers_.CellNo1,tbl_DPos.productid, " + * " productname,proqty,grntttl, tbl_Mpos.createdby,convert(varchar, tbl_Mpos.createdat, 103) as [createdat] " + * " from tbl_Mpos inner join tbl_DPos on tbl_MPos.Mposid = tbl_DPos.Mposid INNER JOIN Customers_ on tbl_MPos.CellNo1 = Customers_.CellNo1 " + * " inner join Products on tbl_DPos.ProductID = Products.ProductID where tbl_Mpos.CompanyId = '" + Session["CompanyID"] + "' and tbl_Mpos.BranchId= '" + Session["BranchID"] + "' order by Mposid desc ";*/ cmd.CommandText = "select tbl_Dstk.productid, ProductName, Dstk_id,Dstk_Qty,Dstk_rat,Dstk_unt from tbl_dstk inner join Products on tbl_Dstk.ProductID = Products.ProductID where tbl_Dstk.CompanyId='" + company + "' and tbl_Dstk.BranchId='" + branch + "'"; cmd.Connection = con; con.Open(); DataTable dtchkcust_ = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dtchkcust_); GVSrchCust.DataSource = dtchkcust_; GVSrchCust.DataBind(); con.Close(); } } catch (Exception ex) { lblerr.Text = ex.Message; } }
protected void GVSrchCust_RowEditing(object sender, GridViewEditEventArgs e) { GVSrchCust.EditIndex = e.NewEditIndex; if (ViewState["getnum"] != null) { DataTable dt_ = (DataTable)ViewState["getnum"]; if (dt_.Rows.Count > 0) { GVSrchCust.DataSource = dt_; GVSrchCust.DataBind(); DropDownList DDL_Pro = GVSrchCust.Rows[e.NewEditIndex].FindControl("DDL_Pro") as DropDownList; Label lbl_Proid = GVSrchCust.Rows[e.NewEditIndex].FindControl("lbl_Proid") as Label; DDL_Pro.SelectedValue = lbl_Proid.Text.Trim(); } } else { FillGrid(); DropDownList DDL_Pro = GVSrchCust.Rows[e.NewEditIndex].FindControl("DDL_Pro") as DropDownList; Label lbl_Proid = GVSrchCust.Rows[e.NewEditIndex].FindControl("lbl_Proid") as Label; DDL_Pro.SelectedValue = lbl_Proid.Text.Trim(); } }
protected void TB_SearchCust_TextChanged(object sender, EventArgs e) { try { /*string query = " select top 20 ROW_NUMBER() OVER(ORDER BY tbl_MPos.Mposid DESC) AS [ID],tbl_Mpos.Mposid,tbl_Mpos.BillNO,billdat,left(billtim,8) as [billtim], tbl_MPos.CustomerName,Customers_.CellNo1,tbl_DPos.productid, " + * " productname,proqty,grntttl, tbl_Mpos.createdby,convert(varchar, tbl_Mpos.createdat, 103) as [createdat] " + * " from tbl_Mpos inner join tbl_DPos on tbl_MPos.Mposid = tbl_DPos.Mposid INNER JOIN Customers_ on tbl_MPos.CellNo1 = Customers_.CellNo1 " + * " inner join Products on tbl_DPos.ProductID = Pr where tbl_Mpos.CompanyId = '" + Session["CompanyID"] + "' and tbl_Mpos.BranchId= '" + Session["BranchID"] + "' and tbl_MPos.CellNo1 ='" + TB_SearchCust.Text.Trim() + "' order by Mposid desc ";*/ string query = "SELECT top 20 ROW_NUMBER() OVER(ORDER BY SS.Mposid DESC) AS [ID], SS.Mposid,SS.BillNO, SS.CustomerName,SS.CellNo1,adv,bal, grntttl,billdat,left(billtim,8) as [billtim], SS.createdby,convert(varchar, SS.createdat, 103) as [createdat] FROM tbl_Mpos SS inner join tbl_DPos on SS.Mposid = tbl_DPos.Mposid INNER JOIN Customers_ on SS.CellNo1 = Customers_.CellNo1 where SS.CellNo1 = '" + TB_SearchCust.Text.Trim() + "' GROUP BY SS.Mposid, SS.CustomerName,SS.BillNO, billdat, billtim, SS.CellNo1,SS.createdby,SS.createdat, adv,bal, grntttl "; SqlCommand cmd = new SqlCommand(query, con); DataTable dt_ = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dt_); if (dt_.Rows.Count > 0) { GVSrchCust.DataSource = dt_; GVSrchCust.DataBind(); TB_SearchCust.Text = ""; lblerr.Text = ""; } else { lblerr.Text = "Sorry No Record Exits!"; FillGrid(); } } catch (Exception ex) { lblerr.Text = ex.Message; } }
protected void GVSrchCust_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GVSrchCust.EditIndex = -1; if (ViewState["getnum"] != null) { DataTable dt_ = (DataTable)ViewState["getnum"]; if (dt_.Rows.Count > 0) { GVSrchCust.DataSource = dt_; GVSrchCust.DataBind(); } } else { FillGrid(); } }